- Home /
How do I reset the rotation?
The coding is a mess, I just starting Unity about a day ago, and everything works fine, but when I use "transform.rotation = Quaternion.Euler(0, 0, 0);" It snaps it back but I want it to slowly rotate back to "0, 0, 0" So how would I implement a new way of doing that? { if (Input.GetKey(KeyCode.W)) transform.Rotate(Vector3.left speed Time.deltaTime);
if (Input.GetKey(KeyCode.S))
transform.Rotate(Vector3.left * -speed * 1 * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
transform.Rotate(Vector3.forward * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Rotate(Vector3.forward * -speed * 1 * Time.deltaTime);
if (Input.GetKeyUp(KeyCode.D))
transform.rotation = Quaternion.Euler(0, 0, 0);
if (Input.GetKeyUp(KeyCode.A))
transform.rotation = Quaternion.Euler(0, 0, 0);
if (Input.GetKeyUp(KeyCode.S)) transform.rotation = Quaternion.Euler(0, 0, 0);
if (Input.GetKeyUp(KeyCode.W)) transform.rotation = Quaternion.Euler(0, 0, 0); } }
Answer by UnityedWeStand · Jun 24, 2020 at 04:41 AM
Use Quaternion.Slerp(). Note that you will need to store the starting rotation. Also, you can use Quaternion.identity instead of Quaternion.Euler(0, 0, 0)
Quaternion startRotation;
float time;
private void SomeFunctionCalledOnceAtBeginningOfRotation()
{
startRotation = transform.rotation;
}
private void SomeFunctionCalledEveryFrame()
{
transform.rotation = Quaternion.Slerp(startRotation, Quaternion.identity, time);
time += Time.deltaTime;
}
Thanks! I'm sure this is the right way, but I do not know how to implement this. Again, I'm very new. I did what I think was right and it did nothing. I even went to the Scripting API for it and tried that and still did nothing.
Your answer
Follow this Question
Related Questions
Why is this rotation not performed as expected? 1 Answer
The object turn but the axis dont (SOLVED) 3 Answers
i need to rotate cube in z axis or x axis one direction at time 0 Answers
Having trouble rotating a turret 1 Answer
How to tilt object towards the direction it's going, while it can be rotated to face any direction? 0 Answers