I tried to make a 3rd Person Camera that fits my needs. But it wasent working like it should…thats the code:
using UnityEngine;
public class CameraController : MonoBehaviour
{
public Transform target;
public Vector3 offset;
public float zoomSpeed = 4f;
public float minZoom = 5f;
public float maxZoom = 15f;
public float pitch = 2f;
public float yawSpeed = 100f;
private float currentZoom = 3f;
private float currentYaw = 0f;
private void Update()
{
currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);
if(Input.GetMouseButton(2))
currentYaw -= Input.GetAxis("Mouse X") * yawSpeed * Time.deltaTime;
}
private void LateUpdate()
{
transform.position = target.position - offset* currentZoom;
transform.LookAt(target.position + Vector3.up * pitch);
transform.RotateAround(target.position, Vector3.up, currentYaw);
}
}
the problem is the zoomfuntion i would like to have the following Properties in the Camera:
Maxzoom = Position x, 0 y 1.8 Z -2.5
Rotation x 26.5 0 0
minzoom Position x, 0 y 9 Z 9
Rotation x 45 0 0
Second Question, i would like to switch from following to aFreecamera and resetting the Position with a keybind. Should i save the defaultposition in a Vector 3 like:
Vector3 defaultCamPos = (0, 1.8, -2.5)
Vector3 defaultCamRot = (26.5, 0, 0)
and is there a way to change my nickname?!