# Mouse Orbit and touch screen

Hi to all,
i modify the “MouseOrbit” script in order to work only on mouse down; on a standard PC works fine…

``````var target : Transform;
var distance = 20.0;
var mySpeed = 250.0;
private var x = 0.0;
private var y = 0.0;

function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
}

function LateUpdate () {
if (Input.GetMouseButton(0)){
x += Input.GetAxis("Mouse X") * mySpeed * 0.02;
x = ClampAngle(x, xMinLimit, xMaxLimit);
y -= Input.GetAxis("Mouse Y") * mySpeed * 0.01;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
var rotation = Quaternion.Euler(y, x, 0);
transform.rotation = rotation;
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.position = position;
}

static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
``````

…but i need to use this script with a touch screen, and there is a problem: i cannot track the finger position when it’s not pressed, so when my finger left the screen, the last know “mouse position” remains the same until i re-position my finger in another place, making the camera rotate too much in the first frame.

I need to use a sort of delay that eliminate this “firs frame problem”… any sugestion?

Thanks

Hello!

Just a quick idea, do an interpolation between the last touch and the actual one , that should smooth your camera movement.

Hope it helps

does this script work. i get the errors: xMinLimit: Unkonow identifier