Ok so I have a FPS control of a turret which is rotated by swiping. I’ve looked at a few swipe control scripts but I can’t get it right yet.
I currently use ‘touch.deltaPosition’ to detect the swiping and rotating the turret based on it. Here is my script:
function Update()
{
for(var touch : Touch in Input.touches)
{
if(touch.phase == TouchPhase.Moved)
{//Swiping?
//Turret movement
x += touch.deltaPosition.x * speed * Time.deltaTime;
y -= touch.deltaPosition.y * speed * Time.deltaTime;
//x = ClampAngle(x, xMin, xMax);
y = ClampAngle(y, yMin, yMax);
var rotation = Quaternion.Euler(y, x, 0);
//turret.transform.rotation = Quaternion.Slerp(turret.transform.rotation, rotation, Time.time * 0.1);
turret.transform.rotation = rotation;
}
if(touch.phase == TouchPhase.Ended)
{
Fire();
}
}
}
When I run this code, the movement is very rigid and inaccurate. I tried using Slerp/Lerp but that completely disabled the rotation.
How can I improve this?
(I posted this in Android section before but received no help)