how to get a "relative" look at rotation?

I’m looking to create something that uses “aiming” variables from a object that can change rotation,

so if the target object is straight in front of the center of the base object, it would read “0,0”
While if the target is to the left it would read "-45,0 " (and 45,0 for the other side)
Or if the target is higher than the center aim, it would read “0,45” (and 0,-45 for lower)

Though if the base were to rotate away from the target, the values would also change to reflect the offset angle.

I tried using the “find look at” node though this only gets world space offsets, not local space.
when i rotate the objects it wont reflect this additional rotation offset

Heres a diagram of the 2D problem, eventually i will have to put in two axis:
So rotating the base should change variables, though rotating the target should not.

To make matters worse the “base” is an externally referenced object (actor variable) while the target is the object itself.

Anybody got an idea how to rig this up in BP?

I created this thinking it would work,
Though when i rotate the target and base at the same times, i see variables changing, though their relative offset is not changing, the values should remain the same.

I’ve tried to do things like this in the past. It’s difficult because of the way rotations are used internally, and they can flip flop between equivalent rotations which makes it hard to use the rotations as values.

That said why are you getting the relative transform?

I wish there was a significantly easier way to read rotations, to be able to use them for the purposes of game logic

MissStabby, look into dot product node (and the math behind it).
It helps you to get a value between 0.0-1.0 if used right, so you get your relative angle.

I agree that rotations in Unreal Engine 4 are difficult to handle because of the sign flipping at 180 degrees. In Unity you can use quaternion.euler and input 0…360 degrees and beyond if you want for example windmill wheel spinning. You just add 1 degree each frame and the wheel spins. In UE4 this turns into a all-time mess because they do not translate Euler angles into quaternions properly and instead of full 360 degree you have to deal with 0…180 and then -180…0 for a full circle. Would be nice if they overhauled their quaternion math, if they use it at all in the source code.

Just do this:

Find Look at Rot
Delta Rot (A = Actor Rotation, B = Look at Rot)
That should give you the value you need, and by using a Delta Rot node the fact that rotators are cyclical is compensated for automatically.

1 Like

DeltaRot… Thanks I’ll look into that for my needs :slight_smile:

I was doing stuff like this, to deal with the flipping

Thanks for the help!
I managed to get it to work, one of the weird things i discovered was that apparently the roll on one object was the pitch on the other one…

Haha, yep, that’s how it looks if you do not have quaternions in your engine :slight_smile:
It is actually a one-liner in Unity.

Works perfect!! thanks! :slight_smile:

Thanks alot that worked great for me.

Jw, why are you showing code from Unity in an Unreal Engine forum?