Hello everyone,
I have a vehicle with a camera for first person view, i want to move the camera (or ‘head’) of the pilot with the mouse.
But if the mouse is not moved it gently aligns with the forward of the car.
I tried this script in the camera but it’s not working: the camera aligns with the same ‘global’ position, even if the car rotates.
I’ve tried different methods but I can’t make it work. This code is the closest I got. What am I doing wrong?
Thank you.
var car : Transform;
var smoothSpeed : float = 40;
var lookSmoothDamp : float = 0.1;
var yRotation : float;
var xRotation : float;
var yRotationVel : float;
var xRotationVel : float;
var carRotation : float;
function Update(){
carRotation = car.transform.position.y;
yRotation += Input.GetAxis("Mouse X");
xRotation -= Input.GetAxis("Mouse Y");
xRotation = Mathf.Clamp(xRotation, -60, 60);
yRotation = Mathf.SmoothDamp(yRotation, carRotation, yRotationVel, Time.deltaTime * smoothSpeed);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
}