- Home /
Rotate to Original Z Rotation
Hi, I need a way to rotate my object to its original rotation on the Z axis. I want it so that it rotates at a given speed (rotSpeed). If anybody could help it would be appreciated if you could do so.
Many Thanks,
Tommy Eaves
Answer by WickeDHypnO · Aug 11, 2015 at 01:56 AM
I think that the easiest way to do this is to create an empty object then parent your object to the empty. It should have the rotation set to zero. From there you can rotate the empty in any direction on any axis, without touching the rotation of your object.
Answer by wesleywh · Aug 10, 2015 at 11:22 PM
I would look into first storing the Z position on "Start()" or at an appropriate time for you.
Second, I would look into
transform.rotation.z
Finally for speed I would look into
transform.Rotate(..., ...);
Here are some helpful links for you:
http://answers.unity3d.com/questions/595467/controlling-the-rotation-speed-of-an-object.html
http://docs.unity3d.com/ScriptReference/Transform.Rotate.html
http://docs.unity3d.com/ScriptReference/Transform-rotation.html
All this should help you get started on learning what to do.
Answer by johnsonnikolaus · Aug 11, 2015 at 05:35 AM
Use Mathf.SmoothDamp:
private int zRot;
private float velocity = Vector3.zero;
public float rotSpeed;
void Start()
{
zRot = transform.rotation.z;
}
void Update()
{
Quaternion.Euler (new Vector3 (transform.rotation.x, transform.rotation.y, Mathf.SmoothDamp (transform.rotation.z, zRot, ref velocity, rotSpeed)));
}
Your answer
Follow this Question
Related Questions
Rotate object around local Z axis 1 Answer
How to rotate object slowly on only Z axis 2 Answers
Rotating an object on Z axis while moving 1 Answer