- Home /
Copy Rotation Direction only on Y Axis.
Hello,
I'm trying to get a cube (grey) to copy a rotation of another cube (purple), but to only restrict the rotation on the Y axis. This is what I mean;
The Grey cube is only allowed to rotate on its 'y' axis. The Purple cube is allowed to rotate on all. I want to be able for the grey cube to rotate only in the direction-z of the purple, but locked on the Y axis.
As you can see here, the purple cube is actually rotated downwards. But the grey cube is not - but still facing the direction of the Purple cube with regards to its Z-direction, but respecting only its Y rotation.
This is what I would like to attempt, however it doesn't actually run like this. This is my code;
float _rotationAngle = _target.eulerAngles.z;
transform.eulerAngles = new Vector3(0, _rotationAngle, 0);
How can I achieve this? Thanks.
Answer by JeffHardddyyy · Jul 03, 2017 at 02:49 PM
So I was reading your question and I got the idea that of one of two things which if it is neither, I'm sorry.
If you are trying to make it so Grey Cube can only rotate on Y, but Purple can rotate any way around If this is the case, I would look into Constraints They allows things to be frozen via certain arguments.
Another thing I got the idea that you were trying to get, was trying to get purples rotation, from white's. or vice versa If this is the case, I would look into Transform.rotation , it allows you to get the rotation of a certain object. I see you used eularAngles, which is something I don't use (probably because I am not good at Quaternions
Hope this helps!