- Home /
Question by
Voky · Jul 22, 2016 at 10:47 AM ·
c#cameramaincamerapinch
Pinch zoom with simultaneously camera moving
Hello, I am making pinch zoom on main camera and I want camera moving up, simultaneously with camera size increasing (and otherwise), so bottom of camera view will always remain same... It's already done, but when is camera orthographicalSize on it's minimal size (0.1) and fingers on screen moving together, position of camera is changing, which isn't nice, so if you have some advice please help.
void Update()
{
// If there are two touches on the device...
if (Input.touchCount == 2) {
// Store both touches.
Touch touchZero = Input.GetTouch (0);
Touch touchOne = Input.GetTouch (1);
// Find the position in the previous frame of each touch.
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
// Find the magnitude of the vector (the distance) between the touches in each frame.
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
// If the camera is orthographic...
if (GetComponent<Camera>().orthographic) {
// ... change the orthographic size based on the change in distance between the touches.
GetComponent<Camera>().orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
// Make sure the orthographic size never drops below zero.
GetComponent<Camera>().orthographicSize = Mathf.Max (GetComponent<Camera>().orthographicSize, 0.1f);
//} else {
// Otherwise change the field of view based on the change in distance between the touches.
//GetComponent<Camera>().fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;
}
=======================================>>>>
=======================================>>>>
if (GetComponent<Camera> ().orthographicSize > 0.1f) {
fakeMagnitudeDiff = deltaMagnitudeDiff;
} else {
fakeMagnitudeDiff = 0;
}
transform.position = new Vector3 (transform.position.x, transform.position.y + (fakeMagnitudeDiff * moveSpeed), -10);
}
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Accurate Pinch Zoom 1 Answer
How to create scaled space? 0 Answers
Object doesn't stick on Camera right Corner?? (Basic Question) 1 Answer