- Home /
How to make one object's rotation match another?
I am quite new to unity.
I have two objects, "Object A" and "Object B". How can I write a script to make Object A automatically rotate to Object B's rotation?
For Example: If object B's rotation is X:5, Y:2, Z:3.2, object A will rotate to X:5, Y:2, Z:3.2.
Thanks in advance
Answer by tanoshimi · Mar 12, 2015 at 07:49 PM
B.transform.rotation = A.transform.rotation;
?
Javascript or C#? Can I have a full script rather than one line?
That line of code is all you need. If you want a full script, create a new one and insert this line :P
Also, it will work for both C# and UnityScript (which is NOT JavaScript!).
B and A are just gameObject variables holding the relevant gameObjects.
That line of code is all you need. If you want a full script, create a new one and insert this line :P
You know what? He will miss references to those gameobjects. ;)
And the title says "match rotation" but in the text "automatically rotate to" sounds more like its wanted as gradual, which is a whole different thing (but easy to look up.)
And the example has all numbers from 1-5. Odd choices for degrees for rotation. $$anonymous$$akes me wonder if the Q is really about looking at a point?
Your answer
![](https://koobas.hobune.stream/wayback/20220613185933im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make my FlashLight start off instead on. 1 Answer
JS and C# how to open in different programs. 1 Answer
Overwrite the value in my List but why? 0 Answers
Multiple Scripts attached to a GameObject vs Inheritance 0 Answers
error CS0029: Cannot implicitly convert type `UnityEngine.ParticleSystem.MinMaxCurve' to `float' 0 Answers