How to make The Best First Person Camera in Unity

  Рет қаралды 12,242

semikoder

semikoder

Күн бұрын

Пікірлер: 47
@MichaelH-zb8gg
@MichaelH-zb8gg 3 ай бұрын
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 = mainCamera.transform.forward; cameraForward.y = 0f; // Ignore the y-axis rotation if (cameraForward != Vector3.zero) { Quaternion newRotation = Quaternion.LookRotation(cameraForward); transform.rotation = newRotation; } } } }
@Hirte2000
@Hirte2000 2 ай бұрын
if i put that script on the player, he will rotate with the camera, but the jittering is back
@MichaelH-zb8gg
@MichaelH-zb8gg 2 ай бұрын
@ElekriGames strange it worked on mine but I'll check it incase I changed any other setting in cinemachine. Will look at it tomorrow.....
@MichaelH-zb8gg
@MichaelH-zb8gg 2 ай бұрын
​@ElekriGames Ok, I see what is wrong. I had two projects runing I've posted the code for use with the character controller. I'll post the code for use with rigidbody tomorrow. Sorry about that....
@Hirte2000
@Hirte2000 2 ай бұрын
@@MichaelH-zb8gg if you could sent the code tomorrow it would be great im stuck like a week with this problem
@MichaelH-zb8gg
@MichaelH-zb8gg 2 ай бұрын
@@Hirte2000 No prob will do...
@controlledsingularity8084
@controlledsingularity8084 4 ай бұрын
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.
@vinhnguyen-o5z
@vinhnguyen-o5z 14 күн бұрын
"You are done." Why are you intimidating me
@stillzen-dev
@stillzen-dev Ай бұрын
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
@SirMust108
@SirMust108 13 күн бұрын
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(); 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 OnMove(InputAction.CallbackContext context) { Vector2 inputDirection = context.ReadValue(); moveDirection = new Vector2(inputDirection.x, inputDirection.y); } public void OnJump(InputAction.CallbackContext context) { if (IsGrounded() && context.performed) { rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse); } } public void OnRotate(InputAction.CallbackContext context) { Vector2 mouseDelta = context.ReadValue(); 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); } }
@JeraldTheBEAR
@JeraldTheBEAR Ай бұрын
Oh wow. Kinda forgot about that fixedupdate kinda thing. I’m gonna go cry now
@nikz000
@nikz000 3 ай бұрын
I just interpolated the rotation values between each fixedupdate in update
@Arctic.Wolves
@Arctic.Wolves 2 ай бұрын
what about godot?
@EuclidStreams
@EuclidStreams 3 ай бұрын
just use late update for camera rotation lol, wtf
@novs735
@novs735 3 күн бұрын
Cool video but not recommend to use motion blur in it. I want to watch those things clearly without pausing
@qroundhawk7149
@qroundhawk7149 15 күн бұрын
Still have jittering, followed all steps.
@Ementss
@Ementss 2 ай бұрын
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.
@forcepower7116
@forcepower7116 Ай бұрын
I kinda agree with you on the use of plugins, but cinemachine, the new input system and textmeshpro are all plugins that should be in Unity from the start if we are honest these 3 plugins are so powerful and Unity itself uses them
@ze1st_
@ze1st_ 4 ай бұрын
but how did cinemachine fix this?
@semikoder
@semikoder 4 ай бұрын
Cinemachine incorporates the solutions I've mentioned at 8:19
@ze1st_
@ze1st_ 4 ай бұрын
@@semikoder thx. But when i enable interpolation my players movement becomes broken wtf.
@vinhnguyen-o5z
@vinhnguyen-o5z 14 күн бұрын
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
@MayKayy
@MayKayy Ай бұрын
Thank you so much you are best!!
@problem1O1
@problem1O1 5 ай бұрын
Cinematic cut-scene tutorial 🙌
@andrescarvajal2981
@andrescarvajal2981 2 ай бұрын
i dont have event OnMouseMove :( why?
@salithaanildesilva1196
@salithaanildesilva1196 2 ай бұрын
How do i get the first person template
@Th3_V3ct0rAT2
@Th3_V3ct0rAT2 3 ай бұрын
Will it work on mobile devices?
@StephHami
@StephHami 4 ай бұрын
how do you add the Cinemachine namespace in my C# scripts
@ZeonplayzYt
@ZeonplayzYt 5 ай бұрын
pls make tutorial on how to make cod mw type movement and camera animations
@sebastiangeraldohirales4935
@sebastiangeraldohirales4935 4 ай бұрын
I can only find the cinemachine 2.9 version
@GamerBoi9000
@GamerBoi9000 2 ай бұрын
it depends on the unity version you're using. Cinemachine 3.x is available after Unity 2023.1 (you have to use a preview version) and 2023.2 (full release)
@Rauza31
@Rauza31 5 ай бұрын
usually when utilising a camera with a rigidbody it is good to have it separated because that also prevents the camera jittering
@blinkachu5275
@blinkachu5275 2 ай бұрын
It also happens on a CharacterController which isn't a Rigidbody, so that doesn't matter
@Rauza31
@Rauza31 2 ай бұрын
@@blinkachu5275 I’ve never experienced this while using a cc before?
@Montigorable
@Montigorable 4 ай бұрын
Thanks for the solution!
@StephHami
@StephHami 4 ай бұрын
where do i get cm3
@StephHami
@StephHami 4 ай бұрын
you have to have the latest version of unity
@sebastiangeraldohirales4935
@sebastiangeraldohirales4935 4 ай бұрын
x2
@StephHami
@StephHami 4 ай бұрын
@@sebastiangeraldohirales4935 ?
@srydustar5754
@srydustar5754 3 ай бұрын
It's crazy how you have to do all those steps in Unity and in Unreal you don't 😂
@exhilex
@exhilex 2 ай бұрын
Totally true
7 Years of Learning Game Development in 7 Minutes
7:28
semikoder
Рет қаралды 22 М.
Why Stairs Suck in Games... and why they don't have to
11:24
Nick Maltbie
Рет қаралды 1,5 МЛН
АЗАРТНИК 4 |СЕЗОН 3 Серия
30:50
Inter Production
Рет қаралды 1 МЛН
Worst flight ever
00:55
Adam W
Рет қаралды 26 МЛН
How I Made a Satisfying FPS Controller
4:38
Lejynn
Рет қаралды 138 М.
Camera follow In Unity: Cinemachine Tutorial | AshDev
9:02
Ash Dev
Рет қаралды 3,4 М.
I Made a Graphics Engine in Scratch
8:27
Zyger
Рет қаралды 141 М.
Optimizing my Game so it Runs on a Potato
19:02
Blargis
Рет қаралды 592 М.
Post-Processing BASICS in Unity
9:25
Willy Dev
Рет қаралды 12 М.
THIRD PERSON MOVEMENT in Unity
21:05
Brackeys
Рет қаралды 1,4 МЛН
Making a Fake Multiplayer .io Game
11:03
Gambit
Рет қаралды 136 М.
Deleting My Indie Game and Starting Over - Nectar Devlog 16
13:10
АЗАРТНИК 4 |СЕЗОН 3 Серия
30:50
Inter Production
Рет қаралды 1 МЛН