Hello!
i have this script that moves the player (rigidbody with gravity) and makes it jump when “Space” is pressed.
The problem is that if I press W,A,S or D while on air, it stops falling and walks in middle-air. It fells only when I release the movement button. Any help?
if (Input.GetKey(KeyCode.W))
{
animation.CrossFade("walk");
rigidbody.velocity = transform.forward * speed;
}
if (Input.GetKey(KeyCode.S))
{
animation.CrossFade("walkBack");
rigidbody.velocity = transform.forward * -speed;
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(0,-rotationSpeed,0);
animation.CrossFade("strafeL");
}
if(Input.GetKey(KeyCode.D))
{
transform.Rotate(0,rotationSpeed,0);
animation.CrossFade("strafeR");
}
if(Input.anyKey == false)
{
animation.CrossFade("idle");
}
// Jumping and attacking
if (Input.GetButtonDown ("Jump") && foot.grounded == true)
{
animation.Play("jump");
rigidbody.AddForce(0,300,0);
}