Question by
luisake · Jan 09, 2019 at 12:58 PM ·
3dcamera-movementfps controllersmoothfollow
Cinematic feel for 3D First Person Camera
Hi you guys :)
Im a graphic designer working on some virtual first person online gallery where you can walk trough and look at 3D objects. Altough i like games, i want the camera movement to be more cinematic and smooth, rather than beeing "gamy" (strictly following the mouse cursor).
There should be some z-offset like in in 2D Games, where the camere moves a bit further before following the cursor again so the whole movement feels like a camera dolly ride. I hope you get what i mean :)
So down there is my script. Im no coding pro, so really looking forward to help from you guys :)
All the best, Luis
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerLook : MonoBehaviour
{
[SerializeField] private string mouseXInputName, mouseYInputName;
[SerializeField] private float mouseSensitivity;
[SerializeField] private Transform playerBody;
private float xAxisClamp;
private void Awake()
{
LockCursor();
xAxisClamp = 0.0f;
}
private void LockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
CameraRotation();
}
private void CameraRotation()
{
float mouseX = Input.GetAxis(mouseXInputName) * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis(mouseYInputName) * mouseSensitivity * Time.deltaTime;
xAxisClamp += mouseY;
if(xAxisClamp > 90.0f)
{
xAxisClamp = 90.0f;
mouseY = 0.0f;
ClampXAxisRotationToValue(270.0f);
}
else if (xAxisClamp < -90.0f)
{
xAxisClamp = -90.0f;
mouseY = 0.0f;
ClampXAxisRotationToValue(90.0f);
}
transform.Rotate(Vector3.left * mouseY);
playerBody.Rotate(Vector3.up * mouseX);
}
private void ClampXAxisRotationToValue(float value)
{
Vector3 eulerRotation = transform.eulerAngles;
eulerRotation.x = value;
transform.eulerAngles = eulerRotation;
}
}
Comment