- Home /
Question by
FIT13398897 · Apr 25, 2017 at 02:30 PM ·
camerasoundlerpcamera follow3rd person camera
Third person Camera With Lerp trouble
Hey,
I've got a script for a camera that follows and orbits around a target using the mouse control but I also want it to have a smooth follow component as well so that the camera follows and catches up to the target as it moves around. Ive tried implementing Lerp but I haven't had any success. I'm very new to Unity so any help would be very much appreciated.
public bool lockCursor;
public float mouseSensitivity = 10;
public Transform target;
public float dstFromTarget = 10;
public Vector2 pitchMinMax = new Vector2 (-40, 85);
public float rotationSmoothTime = .12f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
float yaw;
float pitch;
void Start() {
if (lockCursor) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
void LateUpdate () {
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y);
currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.eulerAngles = currentRotation;
transform.position = target.position - transform.forward * dstFromTarget;
}
}
Thank you.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612120500im_/https://answers.unity.com/themes/thub/images/avi.jpg)