- Home /
Animator dont transition to self or any sub state
Hello,
Here is a picture to explain what I want to achieve:
As you can see, AnyState transitions to JumpAndFall when isGrounded is false, and has can transition to self disabled. The problem is that when the state transitions to wallJump or doubleJump from JumpAndFall, then if isGrounded is true, since the current state is not JumpAndFall, it will transition to the state and then to wallJump or doubleJump again depending on which condition is true. So basically I want to stop AnyState from transitioning to JumpAndFall again as long as the current state is JumpAndFall or any of the "child" states (i.e. states that can only be transitioned from JumpAndFall), in this picture this means as long as the current state is one of the 3 states in the red circle, then don't do the transition from AnyState.
Is there any way to do this? Thanks
Answer by GiyomuGames · Oct 15, 2015 at 02:13 AM
How about: making the transition from your Anim state (I assume this is the state when you character is on the ground) to JumpAndFall when isGrounded is false making a transition from Any state to Anim when isGrounded is true or make 3 transitions (from each of your jump states) to Anim when isGrounded is true ?
Therefore when isGrounded becomes false the animator will be stuck in your red circle, until isGrounded it true again where you come back to your initial state.
Thank you for your answer, this solution works for the example posted. However, when I will have more states that transition from my runAnim state (the state that you call Anim because we can't see the full name on the picture), I will have to add a transition for each of them to the JumpAndFall state with the isGrounded false condition. Also, I won't be able to use AnyState anymore since again, if I have a state e.g. sprinting that transitions from runAnim, then if isGrounded is true since the state wont be runAnim anymore it will transition again and we're back to square one. I can use transitions for each state that should go to JumpAndFall when is grounded is false but I want to avoid having too many transitions. I posted a solution of my own actually involving state machine behavior which to be honest I don't think is much better but for now I'll just wait a bit before deciding what is the accepted answer (my answer isn't showing up yet though). Thanks for the reply! :)
It's just a thought but you could add the condition "Vspeed == 0" in your transition from AnyState to JumpAndFall. This way while you are in the air the transition won't be called.
Right, but the problem is that since Vspeed is the vertical rigid body velocity, when I arrive at the peak of the jump, Vspeed will become 0 (going from positive value to negative), so even if I'm in the air, the condition to go to JumpAndFall will still be true. So it seems like besides my own solution with the state machine behaviour script, I would need to add quite a few transitions to make it work.
Answer by adjnor · Oct 15, 2015 at 09:43 AM
Ok I found how to do this: I created a new bool variable called inAirState in the animator controller, then created a state machine behavior that I put on all 3 states JumpAndFall, doubleJump and wallJump. In the smb script, I set the inAirState bool to true on state enter, and set it back to false on state exit. Finally, the condition to go from AnyState to JumpAndFall now also has inAirState = false, thus while the current state is any of the 3 states in the red circle (above picture), the inAirState bool will have been set to true, otherwise it'll be false. This works but I really feel like it's not a great solution, I thought there could be way to organize my hierarchy maybe with a sub state machine somehow to achieve this but I don't know how. For now I won't mark this as the answer in case somebody comes up with a better way, if nobody replies I'll just put this as the accepted answer.
Your answer
Follow this Question
Related Questions
Identifying a transition to self in StateMachineBehaviour 0 Answers
Create animation transitions via script. 0 Answers
Animation State Machine Script Control Issue 1 Answer
How to make a transition animation, intermediate animation between two main states 0 Answers
State Machine Behaviour public variable not assignable from editor? 2 Answers