Dealing with Rotators

I think I need a serious re-understanding of how I can use rotations and what in my game.

Perhaps part of the issue is that my game is using a locked Axis

But anyway, lets say I have an enemy and it has a turret and I want it to face my player, or more specifically, to know whether my player is to the left or right of it. (so it knows to turn left or right)

My instinct is to break the rotator and compare angles, but the angles in the rotator flip-flop (I understand why this happens, converting from quats to euler internally) but I don’t have a clue how to work with it

Here are some images showing what is happening, what I can’t deal with. The black line is a debug line and I am using the lookat rotation to get the angle for my turret to face

When I cross the centreline the rotation flips to 180 degrees of what it should be

I don’t know how to deal with this? Part of my game is that I want things to be physically controlled, for example, my turret will use a physics constraint and a driver to a specific angle, for example. But how can I know what angle to get it to turn to, because when I try to get the angle this kind of thing happens? Because I am using locked axis it prevent rotation on all but the locked axis so things flip and flop and shake and it’s messy.

How do I deal with this?

Sad one time bump?

How can I deal with this?

For example, the lookat rotation given between the turret and the player rotates on pitch, but the turret to spin needs to change it’s roll! So I break the rot, and feed the pitch from the lookat into the Roll of the turret… and it works… but ONLY when I am on the right of it, when the player goes to the left of it, the lookat yaw flips from 90 to -90 and the pitch reverses direction so…

I put a select float, and change to a -ve version of the pitch (which has to have 270 added to it) based on whether the yaw is -ve or +ve

I finally got it to work… this feels like a very round about and inefficient and extremely inelegant solution


What is a consistent way of drawing out rotators?

I got it to work in this one because ultimately I am just using that resultant rotator to drive a constraint…

In another blueprint I am using a similar lookat to drive a atan2 because I need to tell the blueprint to turn left or right (with torque forces) so it’s even harder
And debugging this takes forever

Hi rodstone,

Please do not bump posts that have not gone unanswered for 4 or more days. This clutters the forums and makes it difficult to parse through. Thank you.

I have same problems with vector math all the time.
One solution to your problem is:
find “looking turret vector” ie. where it looks now.
then find where it should look at, ie vector to target
then find rotator between vectors. ie. opposite operation to rotate vector.

However until now i could not find which one of many rotator and vector math nodes does this.
I know math behind it, but cannot find nodes, their names are weird sometimes.
Calculating that rotator is kind of basic trigonometry (until you try to get rid of gimball effect).

This is game dev, you should know vector math or be ready for pain later. Btw. my friend that is developing first game with me runs away every time i say “vector math”.

Ps. there is one trick that helps to reduce overthinking about local rotations etc.
I use fake\empty root objects as root, then my real in game objects are child in hierarchy of that root object.
This way motion can work on root (ie, world space coordinates) while i can apply additional rotation as relative rotation or location to the root for my actual game objects.

I was actually updating my thread with an example and a temporary solution

This is a good idea.

Perhaps if I understood those “rotator from X” or “XY” nodes I could do this easy