Hello. How can I make one object look at another, but only along one axis(for example, the object will only look at the other by rotating along the x axis and will not move at all along the y/z axes as part of looking at the object)?
2 Answers
2you can find the angle to another point by using arctan like this
` angleToObject = Math.Arctan((position.x - other.position.x)/(position.y - other.position.y)); `
then just rotate to that angle.
edit
in this example you would be rotating around the z-axis but you could use this same method with any other axis.
Try making the object to look at a new point, that's a combination of the coordinates of the two objects, for example:
ObjectA must look ObjectB but only in its X axis:
ObjectA.transform.lookAt( new Vector3 (
ObjectB.transform.position.x,
ObjectA.transform.position.y,
ObjectA.transform.position.z
) );