- Home /
How do I make animation transitions a one-way street?
I am making a platformer. I have already set up idle and run animations for the player, and I've imported them all into an animation controller. There are some other animations, but I'm going to focus on the two states that are inside the red box.
Transisition 1 is the jump event, Transition 2 is the landing event. When the player hits the spacebar and is touching the ground, I set the TriggerJump trigger, and when they land again, I set the TriggerOnGround trigger.
Here are how these transitions are set up in my animation controller:
My animator is set up properly in my code, as the idle -> running and running -> idle transitions work fine (they're boolean).
When the user hits space and the player is grounded, I execute
anim.SetTrigger("IsJumping");
and when the player enters a collision with the ground I call
anim.SetTrigger("TriggerOnGround")
The way I THOUGHT these triggers worked was that in once you call a trigger and a transition from one state to another occurs, you are stuck in that state until some other trigger gets it out of there. There is only one place in my code where I call TriggerOnGround, so I've set a Debug.Log() there to show whenever this is called.
So after all that setup, here's my problem.
As soon as I hit the spacebar, the player quickly flashes to the jump animation then immediatly back to the idle animation. My above mentioned Debug.Log() shows nothing, so the TriggerOnGround event cannot be getting called, so somehow this animation controller is getting from the jump state to the idle state without my manually calling TriggerOnGround.
MORE INFO AFTER SOME RESEARCH:
What's happening is the transition is backing up on itself, and I don't know how to prevent it. If I mute every other transition in the scene except for transition 1, then there should be no way to get out of the PlayerJumpAnimation state. However, even when I mute all other transitions besides 1, I am still seeing this exact same behavior. That means that the state machine remembers it's previous state, and the transition it took to get there. When the trigger is activated, it goes through the transition from Idle -> Jumping, and when the trigger is set back to false interally, it goes BACKWARDS through the transition to the original state. Is there some way to prevent this backup from happening? I want these transitions to be one-way streets.
Answer by Matt1000 · Apr 29, 2017 at 02:40 PM
I'm sorry to tell you but transitions are NOT supossed to be bi-directional... they ARE a one-way thing. What I'd reccommend is to simply change that trigger to a boolean. And simply create one (e.g: Jump) and whenever it starts you set it to true and when OnGround you set it to false. I've always done that and worked perfectely;