How do I consistently know which direction the character will pivot when orienting to movement

I have figured out how to determine if the character will rotate left or right when orienting to movement, but not if the character is doing a complete 180 degree turn. This is my script.

What is a more reliable method for knowing if your character will turn right or left when orienting to movement?

The problem with this approach is that you relay on the Velocity to be different from the character facing direction (which of course is not the case when you start running backwards or if your character has instantaneous turning)

I would suggest:

  1. On Begin Play: Store the Actor Forward Vector
  2. Each Tick (or whenever you need the change): get a new Actor Forward Vector and check the angle between that and the stored vector.
  3. Consider the case where there is 0 difference (currently it will return Right if there is no actual movement)
  4. Store the new Actor Forward Vector to compare to the one you’ll get next time you check.

With this approach you might not check on each frame but for sure you will have to store the Forward vector each tick just in case you happen to need it on the next. You will also need to make sure that the storing of the Forward Vector happens after the check.

So I tried this, and it still only works when not doing a 180, in which case the character may be turning the opposite direction than what the “pivot direction” variable says

And maybe it has something to do with using motion matching? I’m currently using the game animation sample.

This is quite different. When a character is moving back in the animation sample they are actually jogging back. What value would you expect to get there and what are you actually getting. To be honest “which direction the character will pivot” is not as easily determined as you think.

You can check the animation sample’s animation blueprint where you’ll see how the logic is relaying on similar but quite more complicate logic:


It not only gets the previous direction but also makes future predictions.

You can probably try to extract trajectory back from the animation blueprint but I’m not sure what are you actually trying to achieve with that.

P.S.
Check if this node can help you with what you are looking for:

What I’m trying to do is add animations to the game animation sample for flying movement. There have been a lot of complications with getting the trajectory prediction to work while in the air. So far I’ve figured out ways to get most everything to work, mostly by using extra nested choosers in the chooser table. The reason I’m trying to figure out if the character will pivot left or right is to add another enum to my chooser table.

Ideally I could just have all the pivot animations in a single pose search database, but the issues I ran into is that anytime my velocity reaches zero the pose search hasn’t been able to figure out which animation to use next, causing some erratic switching between animations. I believe there may be some complications with generating the trajectory prediction when not in contact with the floor. I think if I can just accurately tell the chooser which way the character will turn I can separate my left and right pivots. (I already got up and down to work just fine).

Perhaps there is a pose search schema that would make all of this unnecessary, but I haven’t been able to create one that is helpful. Since all my animations are very similar (the character is just suspended and the body reacts to direction changes) I think it makes it extra difficult.

I know what you mean. I tried implementing the method I proposed. It woks fine when turning but when you straighten tour trajectory it hits it rapidly goes back and forth over the turning threshold making whatever turn was ending to rapidly trigger.

Take the next lines with a grain of salt as I haven’t played around that much with motion matching.

Try having a linking/undetermined/idle/blend pose between the animations that you describe as “switching erratically”. Maybe you are missing a link or a turn animation when reversing direction.

If you are sure that the trajectory prediction is faulty, maybe you can take a look at it and come up with a solutions that works in your case. The prediction algorithm is surely not that difficult.

P.S. I played around a bit more and this is what I came up with:

It works but the sensitivity value (1200) is arbitrary.

I also tested the motion animation prediction and I don’t see a reason why you wouldn’t be able to use it.

I also thought of a third solution - making the bones not that stiff and letting them to be modified by physics while flying.

1 Like

I think I got it. I actually came up with something similar. Storing the velocity might have worked as well, but I added a scene component to my character blueprint, attached it to the player’s mesh, and parented it to the root bone. Then in my anim blueprint I get the right vector of the that scene component and store it every 0.2 seconds.

I can then consistently compare the stored variable to the current right vector to get the pivot direction.

I also improved my pivoting boolean by comparing the stored variable to the actors forward vector. (Couldn’t compare to the scene components right vector again because every 0.2 seconds they match)

So far this is working well for 180 degree turns and I am able to trigger pivots for much smaller turns now too. Just need to add/tidy up animations to make sure it flows well.