Hi there, I can’t seem to get a smooth camera movement to work on the z axis. I’m working on a 3D top down game and z seems to effect the height since the camera is rotated 90. I’ve tried using FOV but that causes unwanted stretching of the game objects.
Thank you.
using UnityEngine;
using System.Collections;
public class CameraMinMaxZoom : MonoBehaviour {
public float distanceMin;
public float distanceMax;
public float zoomSpeed;
private float distances = new float[32];
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
moveDirection = new Vector3(0,0,Input.GetAxis("Mouse ScrollWheel"));
moveDirection *= zoomSpeed;
// the direction we're moving is positive (zooming in) or negative (zooming out).
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
//We shouldn't be allowed to zoom in more than distanceMin
if (Mathf.Floor(transform.position.y + moveDirection.y) > distanceMin)
{
transform.Translate(moveDirection, Space.Self);
}
}else if (Input.GetAxis("Mouse ScrollWheel") < 0){
//We shouldn't be allowed to zoom out more than distanceMax
if (Mathf.Floor(transform.position.y + moveDirection.y) < distanceMax)
{
transform.Translate(moveDirection, Space.Self);
}
}
}
}