Getting in what angle one object is placed compared to another object.

Hey, I have a mathematical problem.
I have an object somewhere placed in the world and depending on where the player is located around it I want to have a value from 0 to 1. The distance of the player to the object doesn’t matter. Also the Z-Axis doesn’t matter, I only need two vectors. X and Y. I probably need to do something with the Dotproduct, but I don’t know how.

I want to use it to determine from what direction the player is coming towards the object and deform the object away from the player. If possible I would like to avoid Blueprints.

I hope this little drawing of me explains it better:


If you want to deform, it’s easier to just get a vector rather than work with angles. Angles are almost always the wrong solution in graphics!

So, the world-space vector pointing away from the player at the object is Normalize(Object.Position - Player.Position)

Thus, you can transform this vector into object local space by doing Multiply(Inverse(Object.Rotation), Normalize(Object.Position - Player.Position))

Then, add some weighted value times that vector to your vertices, and the object will “deform” away from the player.

If you really, absolutely, need to calculate a “compass direction” from a X, Y pair, look into the Atan2() function. It has “0” at the “X” direciton and “90” at the “Y” direction, and goes between -180 and 180. You may rotate/flip/reinterpret this as you please, based on handedness interpretation and “which way is North.” But, again, I advise against using angles.

You are the best! Worked like a charm. :slight_smile: Thanks for helping me out!