- Home /
how to rotate an object between two angles
Hello everyone.
I've an empty object (its a point which is an rotation point and another object imported from Maya) which is a child to this object. How to rotate this object between for example two angles (-120 and 120 ) on axis y?
Answer by smallbit · Nov 18, 2013 at 06:19 PM
These are pieces of code you will need.
private Quaternion localRotation;
localRotation.y = Mathf.Clamp(value, -angleLimit,angleLimit);
transform.rotation = localRotation;
for Mathf use namespace - > using System;
value can be anything depending on your need like speed*Time.deltatime, or inputAxis. Anglelimit should be of float declared before , or just use raw float value here
I know you marked this as 'Answered', but the solutions is not correct. Quaternions are non-intuitive, 4D constructs that don't use euler angles. The x, y, z, and w parameters go from 0.0 to 1.0. You can use Transform.eulerAngles, but you must be careful. There are multiple euler angle representation for any physical representation, and Unity can change the representation. One one to go is to keep your own Vector3, and treat Transform.eulerAngles as write only.
Your answer
Follow this Question
Related Questions
Euler to Quaternion conversion returns unexpected result at exactly 180 degree rotation on Y axis 0 Answers
Limiting the rotation of an object 1 Answer
Rotation losing precision 0 Answers
How do I make an empty game object rotate towards the mouse? -1 Answers
Trying to get the angle of a camera object based on players forward, is not distance independent 0 Answers