- Home /
Camera Zoom script stops ability to pan
Hi guys sorry if this question seems noobish. I'm trying to get a camera script working. My game is a 3d top down and I want to be able to pan around the camera while being able to zoom in and out smoothly within a range. I got the panning to work fine but when I put the zoom functions in, the panning stops working. PS. Not sure if it matters the camera is child of the player object just so it can be a reference point to the zoom range.
using UnityEngine; using System.Collections;Blockquote
public class CameraZoom2 : MonoBehaviour { public float moveSpeed= 60.0f; public float distance; private float sensitivityDistance = 50f; private float damping = 2.5f; private float min = 10; private float max = 50; private Vector3 ydistance;
void Start () { distance = -10f; distance = transform.localPosition.y; }
void Update () { //Camera Movement var x = Input.GetAxis("Horizontal") Time.deltaTime moveSpeed; var y = Input.GetAxis("Vertical") Time.deltaTime moveSpeed; transform.Translate(x, y, 0); //Camera Zoom distance -= Input.GetAxis("Mouse ScrollWheel") sensitivityDistance; distance = Mathf.Clamp(distance, min, max); ydistance.y = Mathf.Lerp(transform.localPosition.y, distance, Time.deltaTime damping); transform.localPosition = ydistance; } } Any help will be greatly appreciated! Thanks
$$anonymous$$aybe you are overwriting the camera position with this script.
I think its better to use the camera FieldOfView for zoo$$anonymous$$g in/out.
Basically what @$$anonymous$$ said. If the camera is orthographic (which i assume it is since you are making a topdown game) then you can manipulate it's orthographicSize
I can't use FOV because I want it to be 3d. I've tried FOV and when you get far away it stretches everything. Also yeah I think my camera zoom is fixed and overwriting something I just cant figure out how to reword it because I'm still very new to coding.
I'm trying to get the camera to move on xyz with lerp and clamp basically.
Answer by Xxov3rxx · May 15, 2014 at 05:43 AM
I figured it out. I'm not sure if this is the most practical way but I decided to make the camera the child of another empty object and I assigned the movement script to that empty object.