- Home /
Object rotation
I want to rotate an object via control input. I need to create a transform object and use that to define the target rotation so that I can use dt and a rotation speed to slew the rotation. My problem is how do I create the Transform object? I have tried many approaches none of which seem to work.
I need to do it this way because the manner in which rotate uses euler angles with signed degrees of rotation will not allow me to use a Vector3 to define the target rotation.
I wish there was an EulerAngle data type.
I didn't understand what you want to do. Do you want object2 to rotate around an axis defined by object1? Or should object2 rotate at the same speed as object1, but around its local axes?
I want to rotate an object via keystrokes. I want to use dt to rotate it in degrees/sec. Therefore, I need a target rotation to know if I am done rotating the object . What is the best way to create a transform object that I can use to contain my target rotation values?
I solved this by using Get$$anonymous$$ey ins$$anonymous$$d of Get$$anonymous$$eyDown. This allowed me to simply drive the rotation based in the key held condition. THis made all of the target rotation and comparison code disappear. A far superior approach.
But the zero crossing problem for euler angles is a bit of a pimple.
Answer by MattWhiting · Nov 06, 2011 at 11:34 PM
Is this not what you need? Transform.Rotate
You can express your target angles as a Vector3.
Subtract your current rotation Transform.eulerAngles to get the delta.
D a "wrap angle" on it so that your answer is +-180 degrees.
Clamp that to your maximum rotation speed.
Apply Transform.Rotate().
Answer by aldonaletto · Nov 07, 2011 at 12:42 AM
I've just answered what I suppose is a similar question: how to know the exact angle of some object after a rotation. You can't trust in the values returned by eulerAngles after some rotation (it could return (0,180,0) or (180,0,180), for instance).
Take a look at this answer: http://answers.unity3d.com/questions/183603/convert-quaternion-to-eulerangles.html
Your answer
Follow this Question
Related Questions
Having issues with transform.rotation. 0 Answers
2D platformer firing left and right, help! 1 Answer
Calc 30° left and x units forward from local forward axis 1 Answer
Rotation on Android vs. PC 0 Answers