- Home /
How I can identify if the player is going up or down?
Well... I making a metroidvania game, and I need to check if the player is going up or down to change the animations. My idea is (vspeed = vertical speed): If the vspeed > 0.01 (change to animation "going up") else if the vspeed = 0 (change to "in the air") else if the vspeed < -0.01 (change to "falling") I hope you understanding... Well, please, help me @-@
(And sorry my english...)
Answer by Bazzalisk · Jan 19, 2017 at 10:59 AM
//initial values
private float lastVertPosition = 0;
private bool inTheAir = false;
void update()
{
//compares vert position based on last frame
//If the player's vertical position has changed or they're in the air, then go to the sub if statements.
if(lastVertPosition != this.transform.position.y || inTheAir)
{
if(lastVertPosition > this.transform.position.y)
{
inTheAir = false;
//animation falling
}
else if(lastVertPosition < this.transform.position.y)
{
inTheAir = true;
//animation jumping
}
else
{
//animation in the air(no change in vert position, but in the air.
}
}
lastVertPosition = this.transform.position; //setting up for next frame
}
Hope this helps, just came up with it so it might have an error or two. Bazzalisk
Thanks for help, but this don't work... I'm using the animator controller to make my animations. I has made the animations of stand, walk, crawling, crouch... But I can't find a way to make the air's animations how I said. I'm using C# and link the animations with parameters like this: anim.SetBool("Crouch", true)
But... thank you for your help ^,^
Your answer
Follow this Question
Related Questions
Create animation transitions via script. 0 Answers
Mirroring animation clip without mirroring root motion node? 0 Answers
The animation does not play when I click 2 Answers
Sprite collor don't change on animation 0 Answers
how to solve MissingComponentException: There is no 'Animator' attached to the "Ethan 1" game object 1 Answer