Topic locked

Touch/Drag To Rotate Resetting Object Locatio

May 26, 2014 - 7:31pm #1

Hi guys

I have an app I'm building in Unity with Vuforia for Android. (have posted this in Unity also) I've succesfully got the object rotating when i click and drag, and it works on the computer.   It also works on the phone, however, when I tap the object it seems to reset the position of the object.  It's hard to describe but basically it's like it keeps bringing the object back to the starting point.  This isn't happening on the computer.  Heres the code:

<pre class="brush: jscript">

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.LerpspeedVector3.zeroi);   
    }
 
    transform.RotateCamera.main.transform.up * speed.x * rotationSpeedSpace.World );
    transform.RotateCamera.main.transform.right * speed.y * rotationSpeedSpace.World );
 
}

</pre>

Can you see something I'm missing or that would be causing the object to rotate smoothly on computer but constantly snap back to starting point on phone?

 

Regards

Sam

Touch/Drag To Rotate Resetting Object Locatio

May 26, 2014 - 11:47pm #2
Topic locked