- Home /
How do I set the y rotation of one object to another
I'm trying to make a game object move with my cameras rotation. but if I were to parent it I would get unwanted movement. How can I make it so it only rotates around one axis and not the others.
Answer by Anonymous620 · Sep 26, 2021 at 10:49 PM
Object1.transform.rotation = Quaternion.Euler(Object1.transform.eulerAngles.x, Camera.main.transform.eulerAngles.y, Object1.transform.eulerAngles.z);
Edit: eulerAngles as correction of Hellium
If your camera isn't the main one you will need to replace Camera.Main with your referenced camera.
Answer by VoidPhoenix96 · Feb 27, 2021 at 01:20 AM
Here is what you need to do. If you want the two object to have the exact same y rotation, you need to do something like this: Object1.transform.rotation.y = Object2.transform.rotation.y;
untiy just tells me that object.transform.rotation.y is not a variable and therefore cannot be modified please help i have the same problem
You can't set just one vector of a vector3. that is why you are getting this error with this code. you have to address the entire vector3.
Answer by inpeckable891 · Oct 31, 2021 at 03:28 AM
Simple answer, call one transform at the top of your script(this will be the transform that you attach this script to) then call another transform at the top of your script(this will be the transform that you will rotate this' object's transform to) then simple say Transform1.transform.rotation = Transform2.transform.rotation; (make sure to put that in an Update function)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
camera rotation interferes with controller rotation 0 Answers
limiting player rotation 0 Answers