Hi, so I have been having an issue setting up my running, running to jump and falling and falling from high height states. Before I explain my problem, I will explain what I am trying to achieve. What I am trying to achieve is for my character to be able to stand in idle, walk and run, run to jump, I want the run to jump to be smooth so that my character can consecutively run to jump in a smooth fashion. Basically, the problem is occurring when I’m running to jumping consecutively, the first jump is fine but if I jump the second time a bit too fast it is playing the falling animation that I only want to play when the character reaches 300 velocity, basically anything below that I want it to just do the normal run and jump animation that I have setup. Also, another problem is that if the character walks off a ledge, it will play the jump animation, I don’t want that also, I think it is a problem with how my falling Booleans are setup, but I don’t know how to fix it. Instead of typing how my Main State Machine is setup, I will explain it in the video attached to this post. Please someone help me understand what I need to do. There should be a video attached below.
Hi! First of all I wanna thank you for providing such a clear explanation of your issue Now lemme go over all the possible fixes you can consider implementing.
- I think the reason your character enters the falling state as you spam the input that triggers jumping is because it detects that the player is falling at the times when you give the input slightly before your character lands on the ground. You can fix this by adding a prioritized condition before the transition into the falling state begins, which will be bound to a bool type variable which you can set to true after the “Event On Landed” node and set back to false after the jumping node that you trigger on user input.
- You’re right about that the jumping animation gets triggered when the character falls off a ledge due to the transition condition you’ve set there. You can use the same bool type variable we created before to trigger the jumping animation, but this time plug a “Not Bool” node to it before inserting the final result into the transition condition. Once that’s done, the jumping animation won’t play when the character falls off a ledge but we still want it to play the falling animation. To do that, you can create a new transition from your walk/run state to the falling state and insert your variable named “Is Falling?” into the transition condition between those.
- You should be able to get the player’s velocity on z axis by splitting the yellow output pin of the “Get Velocity” node. You can check if it’s magnitude is greater than 300 and transition into a more intense falling animation if it is. Wait! I was tend to explain how to get the player’s velocity on z axis because you mentioned that you had troubles on that matter, but on second thought, what you wanna achieve can be done by detecting the airborne time instead of the velocity, as the velocity on z axis won’t change for the entire duration of the fall. As for the revised suggestion, you can get a “Set Timer by Event” node, insert the desired value into it’s “time” pin, create a custom event and plug it’s red square pin into the “event” pin of the timer. That’s done, now get a branch node, plug your “Is Falling?” variable into it’s condition pin and plug the branch node to the Event Tick node. After that, create a new bool type variable which will indicate that the cricital air time has been reached, and set it to false after the branch node’s false output pin. Then connect the branch node’s true output pin with our timer’s input execution pin. Remember that custom event that we’re dispatching from the timer? Plug the set type node for our critical air time variable to it’s execution pin and set the variable to true. Now instead of the velocity on z axis, you can use this variable to transition into a more intense falling animation.
I hope these can be helpful