Why is "calculate Direction" inverting when the character is turning over 90 degrees?

Hi!
I’m attempting to set up a killer whale to maneuver around a swim volume in Unreal 4.27, but I ran into an issue with the calculate direction node: whenever the character turns over 90 degrees, the node spits out an inverted value, causing the wrong animation to play (turning left instead of turning right or vice versa). Is anyone familiar with this issue and how to fix it?


This is my animation blueprint, with the XAxis variable feeding into my blend space. If there is any more information you need, I’d be happy to supply! Thank you

It looks like you might be getting velocity in world space, but turning animations typically expect the turn direction in character-local space.

Interesting. How would I go about correcting that?

You might start here:

Although, in general, I highly recommend making friends with the various “transform position” and “transform vector” nodes that exist in blueprints, and the different coordinate spaces used by different components for different reasons – those are crucial to making the best use of the engine!

1 Like

So what about my blueprint tells you that I am getting velocity in world space? Because honestly, this still hasn’t solved my issue, and the link you attached appears to be for the anim graph?

I linked the animbp version of those nodes because the screen shot in those questions is of an animbp.
There are similar functions for regular blueprints, too.
The reason it looks like you might be getting animations in world space, is that you claim it stops working when you turn 90 degrees, which is a very common symptom of using the wrong coordinate space.
Also, “Get Velocity” and “Get Actor Rotation” work in world space.

There may be other causes, of course. Unreal coordinate systems are left handed (like a compass rose,) so positive means clockwise, for example.
Also, if you want to know “how much right is this moving,” it’s generally more common to get the “right” vector of the character orientation, and dot product that with the nomarlized character movement (velocity) vector; this will give you a nice -1 … 1 range for “90 degrees left” to “90 degrees right.”

Anyway, those are some things to check!


I am…somewhere around here. It works just the same as it did before, with the same issue. I believe it is in local space? And no more calculate direction.

Also, here’s a video showcasing the issue when I rotate the character. Let me know if you’d like any more information!

The video is pointless if we/you dont know what values or direction to expect.

Re the whole thing.
Right vector is ok on the default mesh to use as forward vector, because some ■■■■■■ a long time ago set the character BP to be rotated by 90d making the red (right) axis the forward vector.
When you trygetpawnowner that may no longer be your forward vector.

Decide first if you want to work local in the animbp or remote, as you properly should, in the character bp.

Based on that, either use the mesh right vector directly, or the actor forward vector…

Also, you can and should just set your blend-space to work in positive/negative.
Path of least resistance.

Hey @IdleTech, it would help to know what values you are using and what values are coming out of the CalculateDirection function. I suggest drawing debug arrows to show the velocity direction and other arrow to show the Character’s Rotation. Also printing the numeric value that comes out of the CalculateDirection method. This way we have more information on the issue.

It might be that the movement of the camera is very fast and the pawn’s rotation is not fast enough to catch up and the differenc between Velocity and PawnRotation is larger than 180, which would mean that it changes the value sign.

A solution might be to calculate the rotation direction in a different way, like saving the value of the characters rotation in each frame and comparing it with its direction in the next frame. That way you have a DeltaRotation and you know in which direction you are moving and play the animation properly.

Hope this helps

1 Like

This ended up being the solution. Thank you so much!

1 Like