Slowing velocity in Rotation?

Hello everyone,

I’m working in a script that makes a 3d Object spin with the mouse. The rotations works very well, then when the 3d object stops and wait for 2 seconds and then return to the origin point of rotation.

But I need to control the velocity of returning, because now is so fast. I tried with Quaternion.Slerp, but I don’t know very well how to put it.

Thanks for your time,

Please see to my Script.

var rotationSpeed = 20; // rotation speed
var rotationStart = 0.0; // rotation on start 
var speed = 0.1; // return speed
 
function Awake () {
transform.Rotate(rotationStart,0,0);
}
 
function Update (){

if (Input.GetButton("Fire1")){

transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
}
if (Input.GetButtonUp ("Fire1")) {
StartCoroutine("Return",2);
}
}
    
function Return(){
yield WaitForSeconds (2.0);
transform.rotation = (Quaternion.Slerp (rotationStart,0,0) Time.time * speed);

}

Thanks in advance

Quaternion.Slerp() needs to be called from or inside Update() so it is called repeatedly. And your method call here is incorrect…should be something like Quaternion.Slerp(transform.rotation, Quaternion.identy, Time.time * speed); Also take a look at Quaternion.RotateTowards() if you want constant speed.