- Home /
Animation playing when NOT grounded
Hey guys,
I am working on a script for player movement and I am up to adding animation cues. Here is a snippet of it within Void Update"
if(movementEnabled) //When there is no count down or anything like that that we should not move during
{
if(Input.GetButton("Left/Right"))
{
playerTransform.Rotate(0, Input.GetAxis("Left/Right") * Time.deltaTime * rotateSpeed, 0); //A and D
}
if (playerController.isGrounded){
Debug.Log("On the ground");
playerMoveDirection = new Vector3(0, 0, Input.GetAxis("Forward/Backward")); //W and S
playerMoveDirection = playerTransform.TransformDirection(playerMoveDirection).normalized;
playerMoveDirection *= skateSpeed;
airTime = 0;
if(Input.GetButton("Forward/Backward"))
{
playermodel.animation.CrossFade("Skate");
}
if (Input.GetButton("Jump"))
{
if(airTime < jumpTime)
{
playerMoveDirection.y =+ jumpHeight;
Jump();
}
}
else
Idle();
}
else
{
Debug.Log("Not on ground");
if ((playerCollisionFlags & CollisionFlags.CollidedBelow) ==0)
{
airTime+= Time.deltaTime;
if(airTime > fallTime)
{
Fall(); //show falling animation
}
}
}
playerMoveDirection.y -=gravity * Time.deltaTime;
playerCollisionFlags = playerController.Move(playerMoveDirection);
}
The problem is that the skating animation only works if I press W or S when I am IN THE AIR. I put it within the check for the controller being grounded but it only works after I jump.
Please help me fix this minor issue. Thanks in advance!
Where is the Fall function? You called it but it would be nice if we could see the function
It's simply
public void Fall()
{
//playermodel.animation.CrossFade("Falling");
}
I only have the idle and skating animation at the moment. I am just preparing for the subsequent animations by calling such a function.
Your answer
Follow this Question
Related Questions
Make the player go into the direction I am looking at 0 Answers
non-rigidbody velocity wrong in x-axis 1 Answer
AnimationController Resets Rotation After TimeLine Animation 1 Answer
Making a non player character move forward 3 Answers
Does Unity have ANY support for ANY Thrustmaster products? 0 Answers