Make rotation of two objects match in Unity3D
Hello, I've been trying to make an object rotate with a second one, so their rotations would match. I am instantiating the second object with Raycast and when it gets instantiated, it's rotation is by bigger than the first object's by 3 units. Is there a way to fix that?
Answer by JoeDarido · Feb 19, 2018 at 06:50 AM
I can see two solutions for that: 1- Instantiate it as a child of the first object, the rotations will be the same and you wont need a code to do the rotation match. 2- The initial rotation of the instantiated object should be the same as the first rotating object, I'm guessing they are starting with a difference of 3 units which is generating your problem
But I am using object1.transform.rotation = object2.transform.rotation
, but it doesn't work. Could it be because of a small delay of the Raycast?
No, the raycast delay (if there's one) is compensated by the update function repeating this sentence of code. The Global Rotations are kept the same but I think it's the local rotation that's making this 3 units difference. Check the instantiated prefab's initial rotation, I think that's what's making the problem.
or simply, ins$$anonymous$$d of using Quaterniun.Identity
in the instantiation line, use transform.rotation
this should override the initial local rotation of the prefab you're using
I've tried this, but still no luck. The prefab's rotation is all 0.