Log in or register to post comments

Touch/Drag To Rotate Resetting Object Location

May 26, 2014 - 7:28pm #1

Hi guys

I have an app I'm building in Unity with Vuforia for Android. (have posted this in Android 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 );


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?




Touch/Drag To Rotate Resetting Object Location

May 29, 2014 - 6:53pm #3

Here's a Dev-Guide article that might help. It explains how to drag an AR object on the screen:



Touch/Drag To Rotate Resetting Object Location

May 27, 2014 - 9:21pm #2


Anyone?  Someone I spoke to pointed me to a TouchScript Asset library but wasn't sure how to implement it (had functions for drag etc but nothing for rotate).

Another person I spoke to says it's something to do with the fact that the camera and touch interface isn't fixed.

Once again the issue is on computer when I click and drag it rotates fine on its axis.  On touch screen when I click it repositions the object before it drags.

It's the last thing I need to do before this bastardchild of an app is done.  I've read about just about every questions that has click, drag, rotate in it, scripts often work fine on computer but don't translate well to touch.

Log in or register to post comments