How to get a basic locomotion with idle, walk, jog, run?
So I am creating a basic locomotion for this Third Person character. I want to have the player go from idle ->walk->jog->run based on it's speed and to turn based on direction. This is my animator control below:
And this my code for the controller:
Animator anima;
// Use this for initialization
void Start()
{
anima = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
hDirection = Input.GetAxis("Horizontal");
vSpeed = Input.GetAxis("Vertical");
//If the Key W is pressed, character will walk else stay at idle position
if (Input.GetKey(KeyCode.W))
{
animSpeed = 0.5f;
animSpeed += Time.deltaTime;
vSpeed = animSpeed;
}
else
{
animSpeed = 0.0f;
}
//If the Left Control Key is pressed, character will jog else stay at idle position
if (Input.GetKey(KeyCode.LeftControl))
{
animSpeed = 1.0f;
animSpeed += Time.deltaTime;
vSpeed = animSpeed;
}
else
{
animSpeed = 0.0f;
}
//If the Left Shift Key is pressed, character will run else stay at idle position
if (Input.GetKey(KeyCode.LeftShift))
{
animSpeed = 1.5f;
animSpeed += Time.deltaTime;
vSpeed = animSpeed;
}
else
{
animSpeed = 0.0f;
}
//Pass the animator parameters to following variables
anima.SetFloat("Speed", vSpeed);
anima.SetFloat("Direction", hDirection);
}
I attached the script to the Character object. The character is still in idle position, even though I pressed the W key to play the walk animation. Can anyone tell me what am I doing wrong? And put me on the right path. Thanks...
Your answer
Follow this Question
Related Questions
thirdpersoncontroller multiplayer animations 0 Answers
I can't assign Third Person Character 0 Answers
Simple Third Person Controller and Animation Script 0 Answers
How do i make my player go from walk animation to run animation using blend trees? 1 Answer
Walk animation only called right as it is switching to another animation 0 Answers