I've been trying to make a function similar to "Find look at rotation" but with an offset. Imagine I have a pivot and an object attached to that pivot with some location and rotation offset. I want to rotate the pivot so that the child object is facing a target.


The blue box is the pivot, the gray is the child object and the red is the target. I've found a method that should work, but I'm having trouble implementing it.

Function This is the function that I've made.

I've asked this question on math stack exchange and this function is based on this answer that I got...

The points that are being referred to in this are:

  • B - The child object location

  • C - A point on the line that goes from the child object along its forward vector

  • D - The target location

  • O - Origin and also the pivot location

...rotate point \$D\$ about an axis passing through the origin, so that \$D\$'s image lies on the line \$BC\$. After we find this rotation, we'll just invert the rotation and apply it to line \$BC\$, to make it contain point \$D\$.

Since the rotation of point \$D\$ about any axis passing through the origin, will be another point that lies on the sphere centered at the origin, and with a radius equal to \$OD\$, then all we have to do to find the image of point \$D\$, is intersect the sphere with line \$BC\$. There can be no intersections, one intersection, or two intersections at most. If there are no intersections, then it is not possible to perform this rotation to satisfy the given condition. Otherwise, pick an intersection, call it \$D′\$ as the image of \$D\$. Now we want to rotate \$OD\$ into \$OD′\$, and this can be done in an infinite number of ways, as the axis of rotation is not unique, but instead lies in the plane whose normal vector is \$DD′\$ and passing through the midpoint of \$DD′\$.

However, there is a rotation that uses the minimum possible rotation angle, and that rotation has an axis given by \$OD\times OD'\$, and the rotation angle \$\theta\$ is given by:

$$\theta = \text{atan2}\bigg( \dfrac{OD \cdot OD'}{ \| OD \|^2 } ,\dfrac{ \| OD \times OD' \| } { \| OD \|^2 } \bigg) = \text{atan2} ( OD \cdot OD' , \| OD \times OD' \| )$$

Plugging the equations above into Geogebra I did indeed get the desired result, but I'm having trouble replicating the same in Unreal.

The result that I get: Problem video

  • \$\begingroup\$ We have some past Q&A about how to do this in 2D: 1, 2, 3, so they may have some insights you can more easily adapt to Unreal. \$\endgroup\$
    – DMGregory
    Commented Nov 22, 2022 at 17:51
  • \$\begingroup\$ I'll check them out, but I've managed to make a 2D solution for this problem myself and converting that to 3D has been the main issue and the reason I posted that question on math stack exchange in the first place. \$\endgroup\$ Commented Nov 22, 2022 at 17:56
  • \$\begingroup\$ Can you clarify what specific snag you've hit in adapting the Math SE answer to Unreal? The more specific you can be about the problem, the better we can target help. \$\endgroup\$
    – DMGregory
    Commented Nov 22, 2022 at 17:58
  • \$\begingroup\$ I've implemented the above function which (from what I can tell at least) does exactly what the equations do and which I've tested in Geogebra and there they work perfectly. Yet in Unreal the child doesn't point exactly at the target and the error seems to vary based on its location. \$\endgroup\$ Commented Nov 22, 2022 at 18:03

1 Answer 1


For anyone wondering, the math is good and the problem was in the way I applied the rotation. Here's the "correct" way to apply it:



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .