- Home /
Rotate an object to match another
Lots of answers already, but I can't find a formula that works for my scenario.
I have 2 objects, with the same parent structure. I want Object B to rotate over time to match the orientation of Object A, using the shortest path. This will be around the y axis with a little bit of movement on the x axis.
Their relative positions to one another will stay the same, although their parent is moving all of the time. I hope local Rotation removes this part of the problem.
How do I rotate one towards the other? I've reviewed RotateTowards, Lerping and Slerping, and I'm happy to use whatever is the best method. I've tried to implement these, but I'm missing some basic knowledge because the rotations are in the wrong direction, or they go the long way around, or around the wrong axis.
Answer by Luis_Gan · Apr 28, 2020 at 06:20 PM
I think this is what you need:
public Transform target;
public float speed;
void Update()
{
transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, speed * Time.deltaTime);
}
Your answer

Follow this Question
Related Questions
Rotate an object (gun) around another (player) to always face the mouse position. 0 Answers
Model Viewer Camera Rotation 0 Answers
How to rotate an object to "sit" on a sphere 1 Answer
The vision of a camera (displayed as a 3D Cone) needs to rotate towards the player 1 Answer
Problem with Rotate() conditions 0 Answers