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…)
//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