Reputation: 35
I would like a GameObject to rotate from it's current position to 0,0,0 when that event trigger is called.
I've updated my code, this does works and does what I want but is it possible to add a 'speed' variable to control the speed at which it rotates back to 0,0,0 after Quaternion.identity?
many thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotate : MonoBehaviour
{
public GameObject spinme;
public float speed;
public void spin()
{
spinme.transform.rotation = Quaternion.identity;
}
}
Upvotes: 1
Views: 108
Reputation: 1507
You can apply a quaternion gradually to an object (in as many steps as you want) so that it changes according to a velocity or time.
That is known as interpolation. For quaternions the interpolation formula is known as SLERP:
https://en.m.wikipedia.org/wiki/Slerp
Investigate how it works in unity3d.
Upvotes: 1