Get yaw to point at X and Y values (2D)

1.9k Views Asked by At

I have $X$ and $Y$ coordinates. I also have another object. I need to figure out how set the yaw of the second object to point at the $X$ and $Y$ coordinates. How can I go about doing this?

1

There are 1 best solutions below

18
On

If the first object is at $(X,Y)$ and the second is at $(a,b)$, the vector from the second to the first is $(X-a,Y-b)$ To get the angle of that vector from the $+x$ axis (is that what you want?) you can use atan2(Y-b,X-a). It worries about the quadrants, unlike $\arctan$