x


Zooming cam by finger gestures

Hello everybody!

I am trying to code a fingergesture: pinching for camera zoom.

It should do following:

  • When beginning with the two finger, the cam shpould stay with its original FOV
  • when moving finger apart, the cam should zoom out, when moving together, it should zoom in
  • when the fingers leave the screen, the zoom should stay
  • when touching again, the new zoom is the start of the new and same procedure.

So, it's a simple zoom ... but the cam jumps just in and out with my code:

    if (Input.touchCount == 2 && Input.GetTouch(1).phase == TouchPhase.Began){

       var pinchLength : float = Vector2.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);

    }

    if(Input.touchCount == 2 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)){

       var deltaLength : float = Vector2.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
       deltaLength = pinchLength - deltaLength;
       deltaLength = deltaLength /90;

       camActive.gameObject.GetComponent(camAutoZoom).pinchStrength = deltaLength;

    }

     if(Input.touchCount == 2 && (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(1).phase == TouchPhase.Ended)){

       camActive.gameObject.GetComponent(camAutoZoom).actualZoom += deltaLength;
       camActive.gameObject.GetComponent(camAutoZoom).pinchStrength = 0;
       deltaLength = 0;

    }

And now put together in camAutoZoom-Script with this simple line:

gameObject.camera.fov =  originalFOV  + actualZoom + pinchStrength;
more ▼

asked Aug 29 '12 at 12:26 AM

RickTick gravatar image

RickTick
41 7 23 26

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3124
x183
x25
x12

asked: Aug 29 '12 at 12:26 AM

Seen: 440 times

Last Updated: Aug 29 '12 at 12:27 AM