reset rotation to fast, how fix please ?

Hi
this next code works but too fast,
and i need to take 2 seconds to return 0,0,0 rotation Quaternion
any idea please…
i am trying deltatime but not work.
please help, i will apreciate so much.

    void Update()
    {
        if (Input.GetMouseButtonDown(0)&&mouseOver==true )
        {
       transform.rotation = Quaternion.identity;
        }
    }
1 Like

Try to use

public float rotSpeed;

void FixedUpdate(){
    transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, Time.deltaTime*rotSpeed);
}
1 Like

i use and need this on a button but still work very very fast …
means , its returns on a click… but i need to return slowly (reset rotation to 0,0,0)

void FixedUpdate()
    {
        if (Input.GetMouseButtonDown(0)&&mouseOver==true )
        {
MyGameObject.transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, Time.deltaTime*rotSpeed);
                }
}

any help please … ?
how reset rotation of an object but slowly.
thanks

Is it always 2 seconds or is a “max speed” you’re looking for?
You could try a coroutine with rotate towards or lerp/slerp.

1 Like
    public float rotSpeed;
    bool mouseOver;
    bool rotate;
 
    // Update is called once per frame
    void FixedUpdate () {

        if (mouseOver && Input.GetMouseButtonDown(0))
            rotate = true;

        if (rotate)
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, Time.deltaTime * rotSpeed);

        if (transform.rotation == Quaternion.identity)
            rotate = false;
    }
1 Like

thansk for help … really … i apreciate so much …
2 seconds average to return . i mean

1 Like

let me try this code thansk again …

1 Like

I think the code Enzzo gave you is correct. You just need to decrease the rotSpeed in the editor. Smaller the value gets, slower your rotation will be.

1 Like