Skip to main content
2 of 2
Cleanup
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

How to rotate two transforms to touch at a point, while preserving forward direction?

I have a transform which I need to point one of its axes in the direction of another game object, without disturbing or rotating the other axes in any way.

Consider the way your hips move around on a horizontal plane, while both your upper and lower body rotate to face the hip bone's position, without turning left or right.

See the waist

How do I achieve the above using Unity transforms in C#?

Controller is moving only on a horizontal plane. T1 and T2 need to point towards this without changing its front facing direction

In this image, both T1 and T2 need to face the controller anywhere it moves without spinning on their Up axis, meaning their forward axis must always remain forward.

While reviewing my question I see Billboarding as a suggestion. I am asking how to billboard both T1 and T2 to the controller without turning their forward directions.

The problem I am facing comes down to the three axes. If I apply LookAt() to the controller, even if setting the x, y, or z, or both xz or xy or zy to 0, there is no way that LookAt() can point T1 in the right direction along the Z and X axes while ignoring the Y. It is always Z rotation only or X rotation only or undesired Y turning as the result. LookAt is causing the front of the body to face away from the front when the controller moves, I need to lock it to face forward, but tilt side to side and back and forth.