Hi, I am currently enjoying your courses (Well done) and I wonder what is the best-practice to sync a jump animation that have multiple phases (Jump Prepare, Flying Up, Jumping Reload, Falling, Landing) in game development. Right now, I "travel" to the animations (Using Animation Tree) when I enter the corresponding states, which works fine von Run/Idle. But with one "Air" state it seems to get tricky end woul dresult in a ton of compelx code. I am currently thinking of having corresponding states in the state machine for each of the jump phases and transition from one phase to the next depending on the velocity.y (Increasing/Decreasing). How can this be done in a professional/clean way? It would be great if you could share your thoughts. Thanks, Stephan
Good question, it'd make for a nice extra text lesson.
I would try to use root motion for that: encode the jump's motion in the animation directly.
Whether you use many states or group several animations together in one state, with many animations, the code gets more complex regardless. It's a balancing act, and you've got to think out of the box to keep the code manageable.
If you wanted to still control the motion from code, so not use root motion, you wouldn't need to split the Air state in 5. For instance, you can have a single animation with an anticipation, jump, and getting up to the peak of the jump.
The way you do that is by first coding the jump/air motion with a capsule shape, then animate based on that speed. You can capture the game in orthographic view and rotoscope the motion in your 3D program.
Then, as the fall can be of different lengths and duration, you would have a separate animation for that, still handled in the Air state:
if _parent.velocity.y < 0.0: skin.transition_to("fall")
Or you could add a Fall state, for instance if you wanted to change controls when the character falls compared to when it jumps.
For the land animation, it depends on how you animate it. If the character has to stay static while it's landing, you'll need a little bit of extra code compared to what we have. At the same time for a playable character you'll take control away from the player and lose in reactivity what you gain in realism.
You can also use features from the animation tree to help you, like animation auto advance with conditions. You can make the character play the land animation upon entering the idle state until the player wants to move. It's all encapsulated in the Mannequiny scene in that case.
thanks for sharing your thoughts. I will work on this in the next days and will let you know my findings/the outcome.