Converting iOS touch input code to standard Mouse input

Hi all,

Basiclly I have a touch rotate thing going on that I want to convert to mouseClick-drag rotate:

//Speed You drag Object at
var speed : float = 0.1;

//How quickly it slows down
var dragFactor= 0.9;

//a storage space for translating touch-drag amount, to convert to object rotation.
static var translationVelocity: Vector3;
static var newTranslationVelocity: Vector3;

//The Sphere collider that is what will rotate, taking the 3d model with it.
var cam: Camera;

function Update () {

    
 ////  new samplecode:  if(Input.GetMouseButton(0)){
   if (Input.touchCount ==1 ){



////How to convert this stuff to mouse-related input?
    
    for (var i = 0; i < Input.touchCount; ++i) {
        
            //Has finger moved on device?
        if (Input.GetTouch(i).phase == TouchPhase.Moved) {
                
                
           ////new sample code: var mouseDeltaPosition: Input.mousePosition;

            //Where is our finger? This is evaluated every frame
            var touchDeltaPosition:Vector2 = Input.GetTouch(i).deltaPosition;
            
           ////new sample code newTransationVelocity=Vector3(mouseDeltaPosition.x*speed,mouseDeltaPosition.y*speed,0);
            
            //Get our translation speed, it will equal touch movement x "speed"
            translationVelocity=Vector3(touchDeltaPosition.x*speed,touchDeltaPosition.y*speed,0);
            
            }
        }
    }

    cam.transform.Translate(-translationVelocity.x, -translationVelocity.y, 0);

    //Apply Drag Factor so the translation slows down
    translationVelocity -= (translationVelocity * dragFactor) * Time.deltaTime;
    
}

any advice on how to cache and read the new input would be awesome, thanks.

AaronC

What modifier key did you define to handle the action aside of the mouse move? (normal is alt / option)
Or more generally how do you want it to work?

Technically all you need to do is compare the previous Input.mousePosition with the current one and use this as delta, given you are in “drag to rotate mode”

Well the plan will be to use left mouse button down to click drag- I am not so sure of the point of a modifier in this case.

Aaron

Oh right, I posted the translation version rather than the rotation version, but the curious part (about storing the delta) remains. Basically I’ve spent many hours trying to figure this out and couldnt get it to work, so looking for some guidance where possible, starting with th iOS version that does work.

Cheers
Aaron

This helped. Sorted!
http://forum.unity3d.com/threads/39513-Click-drag-camera-movement