Calculating angle between 2 points?

Hi. I’m trying to figure out how to calculate angle between 2 points.
“Object 1” and “Object 2” are inside the widget, and are randomly in different coordinates…

Here’s a picture that shows what I’m trying to calculate (it’s the angle of the red line:
widget

Remember Pythagoras?.. :slight_smile:

Well I have never heard of him…

I also tried this (I looked at one instruction that used vectors), but this doesn’t work.

I want to make the blue object turn in that direction wherever the “Object 2” is. above, below, left, or right. Currently, the “blue” object is turning directions, but only rarely in the correct direction.
widget2

Uh i do not see any angle in your pictures, not sure which one you want calculate.

Yes using dot product > Acos is good idea. However you need to draw those two vectors that make your angle, also yes never forget to normalise them dot product works on normalized vectors.

PS.

  • there is look at node in blueprints , if you use 2 locations and set Z=0 in both you can use it for 2d calculations.
  • do not confuse location of actor with relative location between those two. Make triangle, calculate sides, then use dot product to calculate rotation.
  • since this is just 2d you can use pitagoras and trigonometry to find rotation, you need single rotation there

Or just good ol pitagoras .

You can use the formula ATan((object 1 Y - object 2 Y)/(object 1 X - object 2 X)) + 180 if result is negative.

1 Like

It’s this:

2 Likes

It’s red line in that picture. I wanted to calculate angle (or rotation) of that red line that comes between 2 objects and it’s angle here is about 50°.

I’m pretty sure “Look At” doesn’t work with Widget objects.

This worked better, but my object was randomly upside down, even with our without the “+180”.

THIS :point_up_2:is the solution!! … kind of…

This is how it looks in my blueprint:

Now it works perfectly! Thanks everyone for your help!

Ohh… Pythagoras…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.