How to make The Best First Person Camera in Unity

preview_player
Показать описание
I've been playing around with different camera configurations in Unity to achieve a non-jittery camera and I think I might've come across the best solution.

Timestamps:
0:00 - Introduction
0:42 - Chapter 1: Understanding the problem
1:45 - Chapter 2: FixedUpdate vs Update
4:56 - Chapter 3: The solution
5:17 - Chapter 4: The solution part 2
6:18 - Chapter 4: The solution part 3

#unity

--
Music used:
Daystar - Lemon Cake
A Hat in Time - Train Rush [Remix] by Qumu
Cinematic - Aylex
Fortune - Kyatto
Lamp - Kyatto
Once - RYU ITO MUSIC
Рекомендации по теме
Комментарии
Автор

Here's a short explanation of how to actually do this whitout needing cinemachine or other crap:
Step1: create a empty game object. This is the game object you will be moving around in update and represents the target position of your camera.
Step2: create a script that interpolates the position and rotation of your camera towards this empty game object, about 0.6-0.8 of the way per frame will do.
Step3. Done. You are done.

controlledsingularity
Автор

Nice Tutorial. I've updated to 3.0.1 and it works well. The only problem with Cinemachine is setting up player rotation on camera movement. So below is a script to handle the player rotation on camera movement. Put the script below on the player.



using UnityEngine;

public class PlayerRotate : MonoBehaviour
{
private Camera mainCamera;

private void Start()
{
// Find the main camera in the scene
mainCamera = Camera.main;
}

private void Update()
{
// Rotate the player towards the camera every frame
RotatePlayerTowardsCamera();
}

private void RotatePlayerTowardsCamera()
{
if (mainCamera != null)
{
Vector3 cameraForward =
cameraForward.y = 0f; // Ignore the y-axis rotation

if (cameraForward != Vector3.zero)
{
Quaternion newRotation =
transform.rotation = newRotation;
}
}
}
}

MichaelH-zbgg
Автор

Cool video but not recommend to use motion blur in it. I want to watch those things clearly without pausing

novs
Автор

the short answer how to remove jittering is to replace Update() with LateUpdate() method

ariatari
Автор

So the best way to make a first person camera is to not make one and use a plugin, great job, why make a 10 minute tutorial on failed solutions if you're just gonna use a plugin.

Ementss
Автор

wish this existed 2 fookin years ago - too late to change my system now (+ i'm using version 2020) but this will save many devs going forward

stillzen-dev
Автор

Oh wow. Kinda forgot about that fixedupdate kinda thing. I’m gonna go cry now

JeraldTheBEAR
Автор

usually when utilising a camera with a rigidbody it is good to have it separated because that also prevents the camera jittering

Rauza
Автор

i dont have these issues but cinemachine having explosion and some other stuff built in is one less work i will have to do so its great anyways

tPlayerioT
Автор

rotating camera and other stuff is always ass for me. The inspector display one number, eulerAngle display another, which makes clamping kind of a pain

vinhnguyen-oz
Автор

Still have jittering, followed all steps.

qroundhawk
Автор

hi i use your solution and my rotation problem was solved but now i cant control my character because when i want to go forward when i looking right, my character wants to go left :/ the inputs arent change here is my code

public class PlayerController : MonoBehaviour
{
[SerializeField] float moveSpeed;
[SerializeField] float sensitivity = 0.1f;
[SerializeField] int jumpPower;
[SerializeField] Transform camTransform;

Transform groundCheck;
Rigidbody rb;
Vector3 moveDirection;
Vector2 currentRotation;

private void Awake()
{
rb = GetComponent<Rigidbody>();
groundCheck = transform.GetChild(1);
camTransform = transform.GetChild(0);
}

private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}

private void FixedUpdate()
{
rb.AddForce(new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed));
}

public void context)
{
Vector2 inputDirection =
moveDirection = new Vector2(inputDirection.x, inputDirection.y);
}

public void context)
{
if (IsGrounded() && context.performed)
{
rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
}
}

public void context)
{
Vector2 mouseDelta =
currentRotation.x += mouseDelta.x * sensitivity;

currentRotation.y -= mouseDelta.y * sensitivity;
currentRotation.y = Mathf.Clamp(currentRotation.y, -90f, 90f);
}

private bool IsGrounded()
{
return Physics.CheckSphere(groundCheck.position, 0.2f);
}
}

SirMust
Автор

I just interpolated the rotation values between each fixedupdate in update

nikz
Автор

pls make tutorial on how to make cod mw type movement and camera animations

ZeonplayzYt
Автор

I can only find the cinemachine 2.9 version

sebastiangeraldohirales
Автор

How do i get the first person template

salithaanildesilva
Автор

how do you add the Cinemachine namespace in my C# scripts

StephHami
Автор

It's crazy how you have to do all those steps in Unity and in Unreal you don't 😂

srydustar
Автор

@5:22 the "step x" bit made it genuinely hard to follow. Please don't do it in future videos; every youtuber does self-deprecating humor in coding tutorials and it has never been funny and it always makes the concepts harder to follow. Make professional, to-the-point, videos; that's what we are here for. thanks. Otherwise great video.

m-ismm
Автор

just use late update for camera rotation lol, wtf

EuclidStreams