Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Transform player; //main camera
- public Transform targetObject; //the object that camera to orbit
- public float distance = 10.0f;
- public float xSpeed = 250.0f;
- public float ySpeed = 120.0f;
- public float yMinLimit = -20.0f;
- public float yMaxLimit = 80.0f;
- private float x = 0.0f;
- private float y = 0.0f;
- private int xsign = 1;
- //[Zoom]
- public Vector3 lastZoomPosition;
- public float zoomSpeed = 5.0f;
- //buckets for caching our touch positions
- private Vector2 currTouch1 = Vector2.zero, lastTouch1 = Vector2.zero, currTouch2 = Vector2.zero, lastTouch2 = Vector2.zero;
- private float currDist = 0.0f, lastDist = 0.0f, zoomFactor = 0.0f;
- //[Zoom]
- public void OnTouchMoved()
- {
- if (Input.touches.Length == 2) {
- Zoom();
- }else if (Input.touches.Length == 1){
- x += xsign * Input.GetTouch(touch2Watch).deltaPosition.x * xSpeed *0.02f;
- y -= Input.GetTouch(touch2Watch).deltaPosition.y * ySpeed *0.02f;
- y = Mathf.Clamp(y, 0, 90);
- Quaternion rotation = Quaternion.Euler(y, x, 0);
- Vector3 tempDistance = new Vector3(0.0f, 0.0f, -distance);
- Vector3 position = rotation * tempDistance + targetObject.position;
- player.rotation = rotation;
- player.position = position;
- }
- }
- void Zoom()
- {
- //Caches touch positions for each finger
- switch(TouchLogic.currTouch)
- {
- case 0://first touch
- currTouch1 = Input.GetTouch(0).position;
- lastTouch1 = currTouch1 - Input.GetTouch(0).deltaPosition;
- break;
- case 1://second touch
- currTouch2 = Input.GetTouch(1).position;
- lastTouch2 = currTouch2 - Input.GetTouch(1).deltaPosition;
- break;
- }
- if(TouchLogic.currTouch >= 1)
- {
- currDist = Vector2.Distance(currTouch1, currTouch2);
- lastDist = Vector2.Distance(lastTouch1, lastTouch2);
- }
- else
- {
- currDist = 0.0f;
- lastDist = 0.0f;
- }
- //Calculate the zoom magnitude
- zoomFactor = Mathf.Clamp(lastDist - currDist, -30.0f, 30.0f);
- //apply zoom to camera
- player.Translate(Vector3.forward * zoomFactor * zoomSpeed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement