Hello there. I’m new to unity and C#. I got almost everything i wanted on my camera and that is the camera following my character, the camera collision (with raycast), zoom in and out, but the problem i’m having is that my camera is too stiff and i want to smooth it, but dont know how to do it… Also i want to apply a limit to my zoom in and out, but again i dont know how to do it. Here is the script i made:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour{
public const float Y_ANGLE_MIN = -20.0f;
public const float Y_ANGLE_MAX = 50.0f;
public Transform lookAt;
RaycastHit hit = new RaycastHit ();
public Transform camTransform;
private Camera cam;
public float distance = 40.0f;
public float currentX = 0.0f;
public float currentY = 0.0f;
public float sensitivityX = 4.0f;
public float sensitivityY = 1.0f;
private void Start () {
camTransform = transform;
cam = Camera.main;
GetComponent ().fieldOfView = 20f;
}
private void Update () {
currentX += Input.GetAxis (“Mouse X”) * sensitivityX;
currentY -= Input.GetAxis (“Mouse Y”) * sensitivityY;
currentY = Mathf.Clamp (currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);
if (Input.GetAxis (“Mouse ScrollWheel”) > 0)
{
GetComponent ().fieldOfView–;
}
if (Input.GetAxis (“Mouse ScrollWheel”) < 0)
{
GetComponent ().fieldOfView++;
}
}
private void LateUpdate() {
Vector3 dir = new Vector3 (0, 0, -distance);
Quaternion rotation = Quaternion.Euler (currentY, currentX, 0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt (lookAt.position);
if (Physics.Linecast (lookAt.position, transform.position, out hit))
transform.position = hit.point + transform.forward * 0.2f;
}
}
I saw a lot of videos and forums about it but i dont know how to adapt my script to make my camera move smoother and zoom limit… Can anyone help me do it?