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.
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.