Alright so this script basically rotates an object when dragging across the screen with one finger. I would like to make it more “smooth” thou. Ive been trying alot of diffrent things like lerp and slerp and so on but nothing seems to work, so I thought I might as well post the working code here before I give up. I would greatly appricate if anyone knew to to make the rotation more smooth.
#pragma strict
private var oldMousePos : float;
private var curMousePos : float;
var old : float;
var touch1 : float;
var dual : boolean;
function Update ()
{
if (Input.touchCount == 1)
{
touch1 =Input.GetTouch(0).position.x;
if (Input.GetTouch(0).phase == TouchPhase.Began )
{
oldMousePos = (touch1/Screen.width);
old = 0;
}
if(Input.GetTouch(0).phase == TouchPhase.Moved )// This keeps running while finger is held down
{
curMousePos = (touch1/Screen.width) - oldMousePos;
if(!dual){
transform.Rotate(0,((curMousePos-old)*20000)*Time.deltaTime ,0);
}
else{dual = false;}
old = curMousePos;
}
}
if(Input.touchCount == 2 )
{
dual = true;
}
}
float smooth = some_number; // bigger the number the faster it will rotate
Quaternion newRot = transform.Rotate(0,curMousePos-old,0);
transform.rotation = Quaternion.Lerp(transform.rotation,newRot,Time.deltaTime * smooth);
Not tested but it should work. this is c# though but It’s easy to read