- Home /
Implementing a 2D Landing Animation
I'm struggling to find a way to implement a pixel art 2D landing transition animation. Currently, I have it so my character just switches to idle or running, depending on if he has horizontal velocity when he becomes grounded again. However, I would like to add a landing transition. Currently, I have my animations set up as:
//jump
if (Input.GetKeyDown(KeyCode.Space)) {
if (isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
canDoubleJump = true;
}
else
{
if (canDoubleJump)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce*.9f);
canDoubleJump = false;
AnimationManager.instance.ChangeAnimationState(PLAYER_DBL_JUMP);
}
}
//justLanded = true;
//StartCoroutine(EnableTimedBonus());
}
//check for landing animation
if (isGrounded)
{
if (xMove != 0)
{
AnimationManager.instance.ChangeAnimationState(PLAYER_RUN);
}
else
{
AnimationManager.instance.ChangeAnimationState(PLAYER_IDLE);
}
}
else
{
AnimationManager.instance.ChangeAnimationState(PLAYER_JUMP);
}
The ChangeAnimationState() method is as follows:
public void ChangeAnimationState(string newState)
{
//stop the same animation from interrupting itself
if (currentState == newState) return;
//play the animation
animator.Play(newState);
//reassign the current state
currentState = newState;
}
I'm struggling to find a way to identify when my character is landing on the ground. Any help would be greatly appreciated!
Answer by Shameness · Nov 25, 2020 at 06:48 AM
Hey, it seems you want transition between jump animation and walking. To archive that, using Animator asset would be good approach. If you care to know how to, assuming I understand your problem correctly check the key frames below. Landing animation is forced to be played,. Here is link if you want to further info: https://docs.unity3d.com/Manual/Animator.html
Thanks for the input! I'm trying to avoid using the Animator mecanim, and stick to primarily to code for my animations, as I've heard the mecanim can get very messy as the game grows. That's why I have the ChangeAnimationState function.
I think I need to declare a boolean called 'isLanding' and use that as the trigger for the landing animation, but where I'm stuck is in deter$$anonymous$$ing how to know if the character is landing.