- Home /
Rotate Object 2 times for each rotation of other object
Hello guys.
I have 2 objects. When i rotate the first one 360 degrees for example i need to rotate the other 2 times that amount -> 720 degrees.
I also want to be able to rotate the second object counterclowise when the first rotates clockwise.
Assuming the rotator is the object that i rotate 360 degrees and the script is attached to the object i need to rotate twice as much here is the wrong code i wrote
transform.Rotate ( Vector3.forward * rotationMultiplier * rotator.rotation.z);
The rotationMultiplier is 2 for this situation, but i also need to be able to use negative multiplier
Thanks in advance.
Any problem using a negative number? have you tried with negative numbers?
Answer by Sergio7888 · Sep 28, 2016 at 04:21 AM
Try this:
Vector3 originalRotation=transform.rotation.eulerAngles;
transform.rotation= Quaternion.Euler(originalRotation.x,originalRotation.y,rotator.rotation.eulerAngles.z * 2);
Also don't use rotation.z, rotation.z is Quarternion z value not the z angle to get the z angle use rotation.eulerAngles.z
Thank you very much. Working Great!!
(Such a pitty i don't have any remaining points to reward you...)
Answer by tunerakos · Sep 27, 2016 at 06:25 AM
(i cant add comment so i have to post answer to Sergio7888 comment)
There isn't a problem using negative numbers. The object2 rotates to the opposite direction from the object1 when using negative numbers
The problem is that object2 doesn't get the rotation of the 1st object multiplied by the number but it continues to rotate since it is used in an Update function.
This is obvious since i used the transform.Rotate and not the transform.rotation that i am supposed to use. The problem with the transform.rotation is that i have to use the Quaternion and i don't know how to multiply it by the rotationMultiplier.
P.S. i need to rotate over z axis only. The x and y axis must stay untouched.
Thanks for your time and help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093529im_/https://answers.unity.com/themes/thub/images/avi.jpg)