I’ve got a script that is component of a stationary sphere that is used to rotate the sphere by clicking and dragging. It works flawlessly in the editor… when you click on the object and move the mouse, the sphere rotates in the direction you dragged and eventually slows to a stop. But I’m trying to move it to iPad, and now when you touch the object, it spins suddenly to a new orientation before it begins moving. Can someone take a look at this and see what might be causing this weird jump before the rotation begins?
var rotationSpeed = 10.0;
var lerpSpeed = 1.0;
private var speed = new Vector3();
private var avgSpeed = new Vector3();
private var dragging = false;
private var targetSpeedX = new Vector3();
function OnMouseDown()
{
dragging = true;
}
function Update ()
{
if (Input.GetMouseButton(0) dragging) {
speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);
avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime * 5);
} else {
if (dragging) {
speed = avgSpeed;
dragging = false;
}
var i = Time.deltaTime * lerpSpeed;
speed = Vector3.Lerp( speed, Vector3.zero, i);
}
transform.Rotate( Camera.main.transform.up * speed.x * rotationSpeed, Space.World );
transform.Rotate( Camera.main.transform.right * speed.y * rotationSpeed, Space.World );
}
One thing… I have tried changing Input.GetMouseButton(0) to Input.touchCount == 1, as I’ve read that’s more appropriate for iOS, but nothing really changed.