May 7

Week 7 was filled with life so nothing was done on this project. Hopefully I will have some time this weekend. Fingers crossed!


Apr 21

Web playable version

I’m still doing basic stuff such as player control and camera control. I hope I can start going forward with the game logic next week and add another level. I’m rearranging internal scripts atm, so FPS mode is not working in this version.

  • Fixed a bug with player graphics direction when switching between different modes.
  • Mecanim: Followed the tutorial at http://video.unity3d.com/video/7362044/unity-40-mecanim-animation-tutorial. It’s quite nice, the way you can blend animations. Notice how if you wave and run (shift) or run+jump simultaneously it will still wave.
  • Added a little animation when picking up objects. Can’t seem to get the arms animation to stop though. Could be a pro feature.
  • Wave on key R.
  • Lerping the camera zoom in third person mode, to have a smoother movement.

 

So my TODO list is currently looking like this, but the bottom one will have a low priority and probably some new higher ones will be added next week.

  1. Raycast: Shoot it straight down from head and 1m out.
  2. Raycast: When in FPS mode, it should shoot from camera/head and in the looking direction. Cross in the middle?
  3. Show Inventory.
  4. Level clear: When reaching the goal, show some congratulations and move on to next level.
  5. Carry objects: Carry the object above the head? Carry it straight out like now, but with physics so it blocks (harder to fix).
  6. Skyboxes: Different skyboxes for different worlds to set the mood.
  7. Third person camera: Needs to handle objects in the way in between player and camera. Either move camera closer to player or make objects in between transparent.
  8. Virtual Joystick: For touch devices, a virtual joystick should be used in fps mode.
  9. Splitscreen touch device: 2-player split screen should have a 180 degrees rotation for second player for ultimate play on touch pad.

 


Apr 14

Playable Web version
Changes:

  • Changed usage of UsableObjects to always have trigger area the player must stand in, and then player must look at the object to use it. Look to use is done with a Raycast on Usable layer.
  • Added a Pickable layer for picking up objects. This raycast is done every frame. If it is too expensive, I’ll set the raycast at 5fps.
  • New key for using objects and picking up/dropping objects: E
  • Added a shadow on the player using a Projector in orthographic mode. Or should the shadow get larger when jumping (perspective mode)? Also added fake projector shadows on platforms.
  • Sound played when picking up key and opening door.

The carrying of objects is not the best at the moment. Just lift up the object in the air and parent it to the player with physics off. This has some unwanted (?) sideeffects of moving that object through the wall. Also it will get stuck on the movable platform. Also… it is visually in the way. Perhaps it could be semi-transparent.

The raycast is casting its ray from the head diagonally down. This might miss small objects, so not sure if I should cast it from the head and 1m out to straight down to the ground instead. I think it might work better. The raycast for picking objects has same problem, casting it from the feet and straight out 1m. Will miss stuff that is not on the ground. Will experiment with this next week.

 

This is the TODO list:

  1. Carry objects: Carry the object above the head? Carry it straight out like now, but with physics so it blocks (harder to fix?).
  2. Raycast: Shoot it straight down from head and 1m out.
  3. Raycast: When in FPS mode, it should shoot from camera/head and in the looking direction. Cross in the middle?
  4. Level clear: When reaching the goal, show some congratulations and move on to next level.
  5. Skyboxes: I want different skyboxes for different worlds to set the mood.
  6. Third person camera: Needs to handle objects in the way in between player and camera. Either move camera closer to player or make objects in between transparent.
  7. Mecanim: The Mecanim system will be used for animating instead, as it is much more versatile. One mecanim animation should be usable on all models. Speed should match player speed, so it won’t look like the player is floating.
  8. Virtual Joystick: For touch devices, a virtual joystick should be used in fps mode.
  9. Splitscreen touch device: 2-player split screen should have a 180 degrees rotation for second player for ultimate play on touch pad.

Apr 6

Controls are still the same as in week 2, but also the 4 key will do topdown camera mode and free control mode.

Changes from week 2:

  • Switched back to default model, so the jump animation is visible.
  • Added support for multiplayer splitscreen.
  • NGUI ui for usable objects. Try the door.
  • Changed skybox to something with a ground.
  • Switched terrain for a simpler level.
  • Start menu with settings (multiplayer splitscreen)
  • Dying takes you back to your spawn point.
  • Running with shift-key.

I do not have a second level yet, so clearing this level won’t take you to the next one. This will be implemented next week.

Currently my UsableObjects must have a box trigger collider for getting player to know if it is usable. I’ve been thinking that maybe I should use RayCast from the player and a small distance forward to get the usable objects instead. This would simplify creating usable objects, but might be unnecessary CPU work. I will try this out when I get my OUYA.

Playable web version (Requires Unity3D Web Player)

Screen Shot 2013-04-06 at 17.42.09


Apr 2

NGUI gui is progressing. I now have a nicer looking popup when moving to a usable object (door), and when the required items for using that object is in your inventory (when you have the key to the door), a USE-button will appear. When clicking that, the object is used (the door is opened).

I’m going to prettify the code some, then I will upload it this weekend, along with a new playable web version.
NGUI required items


Mar 31

* Got the jump animation to work for default character. But I switched model just for fun. I could not use old animations on new model, so I’ll have to check out the mecanim system some more.
* Point/Click control mode now works.
* Updated the WaypointsMover. Now can pause at each waypoint.
* Added a UsableObject class, which I use on the door. Go near the door and items missing to use the door will show at the top. Will you be able to open the door? 🙂

u,i,o,p: Changes camera mode.
j,k,l: Changed control mode.
1,2,3: A mix of control+camera mode, like it will be in the final game.

Next weeks focus will be on adding a gui with ngui. Also I will probably not use a terrain, but simpler objects and perhaps use a toon shader.

Web version of the project. (Requires Unity3D Web Player)


Mar 20

Simplified SeekSteer and made my own script for moving objects between waypoints. The MovingPlatform now works much better.

/**
 * Attach to object. Moves object between waypoints.
 */
using UnityEngine;
using System.Collections;

public class WaypointsMover : MonoBehaviour {
    public Transform[] waypoints;
    public float waypointRadius = 1.0f;
    public bool loop = true;
    public float speed = 2.0f;

    private Vector3 currentHeading,targetHeading;
    private int targetwaypoint;
    private Transform _transform;

    protected void Start () {
		enabled = false;
        _transform = transform;
        if(waypoints.Length <= 0) {
            Debug.Log("No waypoints on " + name);
            enabled = false;
        }
        targetwaypoint = 0;
    }

    protected void Update() {
        if(Vector3.Distance(_transform.position, waypoints[targetwaypoint].position) <= waypointRadius) {
            targetwaypoint++;
            if(targetwaypoint >= waypoints.Length) {
                targetwaypoint = 0;
                if(!loop)
                    enabled = false;
            }
        }
		_transform.position = Vector3.MoveTowards(_transform.position, waypoints[targetwaypoint].position, Time.deltaTime * speed);
    }

    // Draws red line between waypoints, and sphere with radius
    public void OnDrawGizmos() {
        if(waypoints == null)
            return;

        for(int i=0;i< waypoints.Length;i++) {
    	    Gizmos.color = new Color(0.9f, 0, 0, 0.3f);
			Gizmos.DrawSphere(waypoints[i].position, waypointRadius);
	        Gizmos.color = Color.red;
            Vector3 pos = waypoints[i].position;
            if(i>0) {
                Vector3 prev = waypoints[i-1].position;
                Gizmos.DrawLine(prev,pos);
            }
        }
    }
}

Mar 19

Player controller.
1,2,3 switches control mode.
1: FPS style. asdw/arrows for movement and mouse for looking.
2: Third person view. asdw/arrows for movement and looking.
3: Top down view. Same as above.
2,3: Raisable camera with mouse scroll wheel.

Switch pad with button. Walk on it to trigger the movable platform. Alternatively push the box onto it, so you can jump up on the platform. The movement script for the platform is … bad. Too be continued.

Web version of the project. (Requires Unity3D Web Player)


Mar 19

 

So I wanted to use an interface reference as a public variable, but it wouldn’t show up in the inspector. After many hours researching and trying different things, I finally settled for using abstract classes instead, and using the unity way of adding scripts to objects as my interface.

I made a pad with a button on it. This button is my switch. When something (player or box) moves onto it, it should trigger an event in another target object. So I wanted to have a SwitchTrigger interface for the target of my switch object.

class TargetObject : MonoBehaviour, ISwitchTrigger {
...
 void OnSwitchTrigger(bool on) {
  // This object has been turned on/off.
 }
}

What I did instead was the following:

/* This should have been an interface, but Unity don't
 * allow interface objects as public references in the gui.
 * */
using UnityEngine;

public abstract class SwitchTriggerTarget : MonoBehaviour {
	public abstract void OnTriggerSwitch(bool on);
}

Then I have to create an explicit class inheriting this abstract class for the specific GameObject I want it on.

public class MovingPlatformTriggerTarget : SwitchTriggerTarget {
	public override void OnTriggerSwitch(bool on) {
		Debug.Log("Platform got trigger=" + on);
		GetComponent<SeekSteer>().enabled = on;
	}
}

I then add the script SwitchTriggerTarget to my MovingPlatform object.

MovingPlatform object also has a MovingPlatform script, which basically just makes sure other objects on MovingPlatform object follows it when it moves. This is done by parenting.

public class MovingPlatform: MonoBehaviour {
	// TODO: Add objects on platform to an array.
	// Save old parent on enter, reattach old parent on exit.

	void OnTriggerEnter(Collider other) {
		other.transform.parent = gameObject.transform;
	}

	void OnTriggerExit(Collider other) {
		other.transform.parent = null;
	}
}

The platform movement is done by another script. Just add the modules you want onto the GameObject, and then make a prefab of it. Modular and nice.

Now, my SwitchPad (the one you walk on to trigger the button), looks like this.

public class SwitchTrigger : MonoBehaviour {
	public SwitchTriggerTarget triggerObject;
	public AnimationClip onClip;
	public AnimationClip offClip;
	private int cnt;

	void Awake() {
		cnt = 0;
		if (onClip)
			GetComponent<Animation>().AddClip(onClip, "on");
		if (offClip)
			GetComponent<Animation>().AddClip(offClip, "off");
	}

	void OnTriggerEnter(Collider other) {
		cnt++;
		if (cnt == 1) {
			// Send trigger message to linked object.
			if (triggerObject) {
				triggerObject.OnTriggerSwitch(true);
			} else {
				Debug.Log("No trigger object attached.");
			}

			// Play on animation, if available.
			if (onClip)
				GetComponent<Animation>().Play("on");
		}
	}

	void OnTriggerExit(Collider other) {
		cnt--;
		if (cnt == 0) {
			// Send trigger message to linked object.
			if (triggerObject)
				triggerObject.OnTriggerSwitch(false);

			// Play off animation, if available.
			if (offClip)
				GetComponent<Animation>().Play("off");
		}
	}
}

The highlighted row: By using the abstract class as the type, only GameObjects with scripts inheriting from SwitchTarget, like MovablePlatformSwitchTarget, can be dragged onto the target in the inspector.

This works, but everything would have been easier if an interface could be used as type and shown in inspector…


Mar 18

I recently found Unity and fell in love. I have been playing with it for a few days now and have started on a game. I like how modular you can make everything with the scripts you attach to the objects.

I hope anyone reading will help if I do something in a bad way, and hopefully somewhere along the ride I can help someone else with my scripts.

I have experience in C, C++, Java, Javascript, but not C#. Although, I am going for the C# route, since it seems like the better way to go.

The game will be a Mario 3D type of game. Walk around and solve puzzles. I will try to upload a web version every sunday, if there has been any progress.