Hi everyone, i am currently trying to create a simple jump player.
So far i can make the player move and jump and detect when its on the ground.
I have hooked this up to a sprite animation, so you get a jump animation when jumping, a walk animation when walking etc.
One issue i am finding is if you jump and move at the same time, the animation will not reset to idle until you let go of the arrow key. This will leave the player on the floor in the jump animation.
my code is as follows :
if (jumping == true) {
hit = Physics2D.Raycast(transform.position,Vector2.down);
Debug.Log (hit.distance );
if (hit.distance < 0.008f){
jumping = false;
}
}
Debug.Log (jumping);
Debug.Log (moveHorizontal);
Animating (moveHorizontal);
}
void Animating(float moveHorizontal)
{
//Debug.Log (moveHorizontal);
if (moveHorizontal != 0f && jumping == false ) {
anim.SetInteger ("status", 1); // Plays walking animation
}
if (moveHorizontal == 0f ) {
anim.SetInteger ("status", 0); // Plays idle animation
}
if (jumping == true) {
anim.SetInteger ("status", 2); // Plays jumping animation
}
}
Is my issue down to the animating void will not kick in until the other action of me holding move is complete hence why the animation status wont change.
using debug, all the criteria of movement not = 0 and jumping = false are in place but the staus wont change.
Any help would be cool.
Thanks