- Home /
[Solved]Double Jump animation Unity 2D
Hi, How i Make double jump animation system using 2D mode in unity? I think this:
if (Input.GetKeyDown (KeyCode.Space) && Pulo == 1) {
anim.SetInteger("estado", 1);//Jump one
}
if (Input.GetKeyDown (KeyCode.Space) && Pulo == 2) {
anim.SetInteger("estado", 2);//Jump two
}
if(!grounded){
anim.SetInteger("estado", 3);// Falling animation
}
But not work! :/
Answer by SunriseKingdom · May 02, 2014 at 07:02 AM
In my animator, I make a Parameter - Bool and name it Jump, and if it True the player go to Jump animation and if it false it go back to normal or walking animation.
But you also want a fall animation and one more jump animation, so create one more bool name it Jump2.
then in the animator under theirs condition use a Exit Time and set it to 5.00, that it will go into the fall Animation.
and on the fall animation set if jump and jump2 is false and Exit Time 8.00 go to Idle.
I post a Image so it will be easy
Code
var jump : boolean = true; //Can you jump
var jumpspeed : int = 5; //How high you can jump
var howmanyjump : int = 2; //How many jump you can make
var addjump : int = 0; //Count up how many jump you made
var anim : Animator;
function Update () {
if (Input.GetKeyDown (KeyCode.UpArrow))
{
if (jump == true)
{
addjump += 1;
rigidbody2D.velocity.y = jumpspeed;
anim.SetBool("Jump",true);
if ( addjump == 2 )
{
anim.SetBool("Jump",false);
anim.SetBool("Jump2",true);
}
if (addjump >= howmanyjump)
{
jump = false;
}
}
}
}
function OnCollisionEnter2D(other : Collision2D)
{
if(other.gameObject.tag == "Ground")
{
addjump = 0;
jump = true;
anim.SetBool("Jump",false);
anim.SetBool("Jump2",false);
}
}
hope this help.
@Sunrise$$anonymous$$ingdom How do you make a transition from jump animation or jump2 animation to fall animation. I mean under what condition do they change and under what condition does the fall change to idle. Because if you are using time for each animation states then it wont be working most cases such as if you hit a wall on top or your landing platform is at different height or very below. So is it possible that we can trigger the idle animation if there is a downward motion in the y axis to be more acurate. I mean a transition from upward motion to downward motion,at that moment can I trigger the fall animation and let it play untill the player hits the ground where it will change form fall to idle anim?