Get Angle between actors?

Hi, should be just the yaw part of FindLookAtRotation (although I can’t tell you whether A´s location needs to be start and B’s end or the other way around, I can never remember that). Basically FindLookAtRotation gives you the rotation you would need to rotate an actor at a certain location so that its forward vector would point to the other location. So in your image, the vector from A to 0 would be the global X-Axis.

Look at rotation is what you want, but in Z ( is this picture from above? )

Also it always returns -180 to 180.

What’s the point of knowing the angle from A to B, what are you intending to do.

Hi, I’m trying to figure out how to get the angle between two actors by 2D. I’ve been playing with the Find Look at Rotation but am getting lost in how to convert the rotator into what I want. So in the ref image, the angle by this calc between Actor A and B would be 43. I don’t really care where 0 (360) sits, I just want to be able to find relative world location between the actors based on the angle.

I just want to be able to find
relative world location between the
actors based on the angle

If you mean that you want a location that lies on the vector from A to B, then you can get that vector (location of B - location of A) and then just multiply it with a number between 0 and 1 and add the location of A to it. So multiplying with 0 would just give the location of A, multiplying with 1 the location of B and e. g. multiplying with 0.5 the location in the middle between A and B.

Thanks you guys. Sorry, I shouldn’t have thrown ‘location’ in there, its not really relevant.

So my objects are aligned in X location. The lookatrotation X-axis only returns 0 and 180. The Y-axis returns degrees, but they do not fit with my desired output (eg, from 0 to 360) This is what I get:

I can see how combining the X-axis and Y-axis returns with a bunch of remapping, <> and select ints could translate these values into what I want - I was just hoping there was a cleaner/faster way of doing this?

Picture above is what Y-axis is returning. X-axis returns either a hard 0 or 180 (depending which X side of B that A is). My end goal (besides trying to lose all my hair) is to determine if Actor B is to the left / to the right / above / below Actor A using minimal code. Maybe I’m overthinking this?

Rotating a vector that is pointing in X-Direction in roll value won’t change the vector. Therefore you can choose any roll rotation that you want, it won’t tell you anything here. Yaw will tell you about left and right and pitch about up and down. For the pitch rotation, values bigger than 90 or smaller than -90 degree won’t make sense, since straight up is 90 degree and straight down is -90. Therefore e. g. 110 would be the same as -70.

The result of FindLookAtRotation won’t directly give any information about how the actors are to each other. For that you also need to take the current rotation of your actor into account. FindLookAtRotation gives you the rotation your actor would need to point to the other location, the difference between both rotators (LookAtRotation and rotation from actors forward vector) should give you the information about left/right (yaw of the rotator positive or negativ), up/down (pitch of the rotation positive or negativ), you would also need to check which is which.

Ok, thanks for all your time guys. I tried using Rotator Delta with LookatRotation and the rotation of the target, but even with that I can see I will have to code a bunch of manual checks to find the info I am after. Looks like maybe thats just the way it is in UE.

if you’re just trying to find out above/below, left/right, you need to subtract location B from location A and see if the result is positive/negative, this will tell you which direction Actor B is

for example, if the first branch is true, then Actor B is to the left of Actor A

So to get to the result reference in the OP, you’d:

That’s providing I understood the intentions correctly. ofc. :slight_smile:

Looks like maybe thats just the way it
is in UE.

The below would give you -180 | 180 range:

328203-screenshot-2.jpg

So you can translate it into whatever other range you need:

Image from Gyazo

Here, I’m adding 180 to the result.

3 Likes

Thank you Everynone, works a charm. Just piped in Z to Y on the V2D and set Angle Deg to +90 and bombs away, I am getting what I want very easily! I didn’t know about these 2d vector nodes, thanks again for enlightening me!

Hi! I came here to thank you all so much! I’ve been stuck developing my game because of this problem. I knew the math but didn’t know how to translate it to blueprints. TYSM! <3

im sorry, but there appears to be a missing post here…what gets plugged into the vector2d nodes that you subtract?

It’s not missing. These are the 2 screen locations you wish to base the calculations on. It’s up to you to provide them.

In this case (the animation), it would be the white square coordinate and the location of the mouse.

1 Like