Hi,
Thanks in advance for help.
I’ve attached the code below to a cube. When I press the left mouse button and drag it the cube’s rotation follows the mouse cursor. When I release the button the cube immediately stops. I am trying to find a way to have the cube finish its rotation, decelerating, after the button release rather than immediately stopping.
{
private int speed = 12;
private float friction = .3f;
private float lerpSpeed = 10.5f;
private float xDeg;
private float yDeg;
private Quaternion fromRotation;
private Quaternion toRotation;
void Update ()
{
if(Input.GetMouseButton(0))
{
xDeg -= Input.GetAxis("Mouse X") * speed * friction;
yDeg += Input.GetAxis("Mouse Y") * speed * friction;
fromRotation = transform.rotation;
toRotation = Quaternion.Euler(yDeg,xDeg,0);
transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
}
}
}
Thanks again!