Hi,
I got my character to jump via the alt key, but I want it to go back to the idle state once finished. Whats the easiest way to do this? it sticks on the jump state and dont know code wise or via the editor how I can get it back to idle states once the jump animation has finished.
Thanks
Dave
Hi Dave,
Do you mind providing a snippet to your code, or at least explain the flow of states in your animator editor?
With the current Mecanim system, it is very easy and convenient for you to apply transitions from states to states.
“A trigger parameter is a bool parameter that gets reset to false when it has been used in a transition. For state machines with multiple layers, the trigger will only get reset once all layers have been evaluated, so that the layers can synchronize their transitions on the same parameter.”
1 Like
if (Input.GetButton("Fire2"))
{
animator.SetBool("runjump", true);
}
so within animator it’ll go from idle to the jump state all good.
but how do i know when the jump state has finished. thats the bit i’m stuck on.
how do you define the grounded state? you can use a function with a concept similar to the character controller’s isGrounded function to return a boolean to set when your jump state finishes.
or, you can use AnimatorStateInfo to return the state of the current playing animation, then return a true boolean for the jump anim to end.
1 Like
Thanks guys,
I got it working using the trigger method and I’m sure the animatorstateinfo will come in useful at some point also:)
Thanks
You could also just create a transition back to idle based on Exit Time where the time is the length of the animation (which I think is the default anyway).
1 Like