Third Person Help

could anyone start me of with a simple script which would play an animation and make my character move forward when I press w? I don’t want anyone to write a massive script which would take ages, I just want something simple. Or could anyone tell me of a good tutorial which would show me how to, ive tried the tut that unity provides but I cant get it to work.

Hi,

This will be exactly what you need to get started.
http://unity3d.com/support/resources/tutorials/3d-platform-game.html

If you want something to happen when you press a key you just need to check if that key was pressed and then just do whatever it is you want to do. For example, to play an animation and move your character forward when you press the ‘w’ key, you would write something like this (c#):

using UnityEngine;

public class Move : MonoBehaviour
{
	/*This will determine how fast the character will move, not how fast the animation plays,
	 * You'll have to make sure it matches your animation manually
	 * Either by changing the animation clip itself, or by adjusting the animation's speed property
	 * e.g: animation["MyAnimationName"].speed = MyValue;
	 */
	public float WalkSpeed = 5.0f;
	
	// Update is called once per frame
	void Update () 
	{
		/*check if we pressed the desired key (will continue to return 'true' while the key is pressed
		 * This is different than Input.GetKeyDown("w") which will only return true once, when the key was actually pressed
		 */
		if (Input.GetKey("w"))
		{
			/*Call the animation to play by name. This will crossfade between animations so you'll get smooth
			 * transition between animations and won't 'snap'
			 */
			animation.CrossFade("Walk");

			/*This will move the character forward by the speed value. However, this will move the character 
			 * 5 units every frame, which is far too fast. To tone things down we multiply it by Time.deltaTime,
			 * or the time since the last frame to create smoother and slower movement 
			 */
			transform.Translate(Vector3.forward * WalkSpeed * Time.deltaTime);
		}
		else
		{
			//if we're not moving we'll want to crossfade back to the idle animation
			animation.CrossFade("Idle");
		}
	}
}

Shouldn’t really be this long, if you’ll skip all the green text :slight_smile:

Did you ever think of adding a third person controller?

Excellent script. Simple but very useful !