- Home /
Troubles with 2D character anims with multiple states
Hello, very new to Unity: 2nd day in. As practise I am trying to recreate Samus (Metroid) movements from the SNES sprite-sheets within Unity.
My problem currently lies with falling and jumping. It's difficult to explain everything without posting a screenshot of my Animator state machine as there are lots of animations depending on where the player is facing.
My questions are
1) How do you determine when a 2D character "jump" animation should stop, before a "fall" animation begins? Currently I am measuring rigidbody2D.velocity.y;
with some bools on the animator to differentiate the direction of the player:
float vSpeed = rigidbody2D.velocity.y;
if (!falling) {
// Check if we're in the air.
if (!grounded && vSpeed > 0.2) {
// Set the jump animation.
if(facingRight) {
animator.SetBool("JumpLeft", false);
animator.SetBool("JumpRight", true);
}
else {
animator.SetBool("JumpLeft", true);
animator.SetBool("JumpRight", false);
}
}
}
// Check if we're falling.
if (!grounded && vSpeed < 0) {
// Set the fall animation.
if(facingRight) {
animator.SetBool("FallLeft", false);
animator.SetBool("FallRight", true);
}
else {
animator.SetBool("FallLeft", true);
animator.SetBool("FallRight", false);
}
}
This may be a schoolboy error but my "fall" code doesn't seem to run when a jump animation has finished.
2) My code is already becoming cluttered with "SetBool" calls to the Animator to trigger the various states. Is this normal for complex 2D character animations? I would like to tidy things up a bit.
3) Is there a better way of handling multiple states for 2D characters? Think: look left, gun triggered left, gun triggered up, gun triggered diagonally down, gun triggered down, falling gun triggered down, etc. etc. I would potentially have to handle quite a few states; is there a way to compartmentalise those, yet have them remain in the same... thing? :)
Thank you!
Your answer
Follow this Question
Related Questions
What is wrong with my Counter Script? (C#) 1 Answer
Distribute terrain in zones 3 Answers
Using Texture Assets in Code 1 Answer
Multiple Cars not working 1 Answer