How to make The Best First Person Camera in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024

ความคิดเห็น • 42

  • @controlledsingularity8084
    @controlledsingularity8084 4 หลายเดือนก่อน +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.

  • @MichaelH-zb8gg
    @MichaelH-zb8gg 2 หลายเดือนก่อน +6

    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;
    }
    }
    }
    }

    • @ElekriGames
      @ElekriGames หลายเดือนก่อน

      if i put that script on the player, he will rotate with the camera, but the jittering is back

    • @MichaelH-zb8gg
      @MichaelH-zb8gg หลายเดือนก่อน

      @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 หลายเดือนก่อน

      ​@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....

    • @ElekriGames
      @ElekriGames หลายเดือนก่อน

      @@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 หลายเดือนก่อน

      @@ElekriGames No prob will do...

  • @problem1O1
    @problem1O1 4 หลายเดือนก่อน +1

    Cinematic cut-scene tutorial 🙌

  • @MayKayy
    @MayKayy หลายเดือนก่อน

    Thank you so much you are best!!

  • @Montigorable
    @Montigorable 4 หลายเดือนก่อน

    Thanks for the solution!

  • @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

  • @ze1st_
    @ze1st_ 4 หลายเดือนก่อน +3

    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.

  • @Rauza31
    @Rauza31 4 หลายเดือนก่อน

    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 หลายเดือนก่อน +1

      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?

  • @JeraldTheBEAR
    @JeraldTheBEAR หลายเดือนก่อน

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

  • @nikz000
    @nikz000 2 หลายเดือนก่อน

    I just interpolated the rotation values between each fixedupdate in update

  • @StephHami
    @StephHami 4 หลายเดือนก่อน

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

  • @andrescarvajal2981
    @andrescarvajal2981 หลายเดือนก่อน

    i dont have event OnMouseMove :( why?

  • @salithaanildesilva1196
    @salithaanildesilva1196 หลายเดือนก่อน

    How do i get the first person template

  • @Th3_V3ct0rAT2
    @Th3_V3ct0rAT2 3 หลายเดือนก่อน

    Will it work on mobile devices?

  • @Arctic.Wolves
    @Arctic.Wolves หลายเดือนก่อน

    what about godot?

  • @ZeonplayzYt
    @ZeonplayzYt 4 หลายเดือนก่อน +1

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

  • @sebastiangeraldohirales4935
    @sebastiangeraldohirales4935 3 หลายเดือนก่อน

    I can only find the cinemachine 2.9 version

    • @GamerBoi9000
      @GamerBoi9000 หลายเดือนก่อน

      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)

  • @Ementss
    @Ementss หลายเดือนก่อน +3

    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

  • @StephHami
    @StephHami 4 หลายเดือนก่อน

    where do i get cm3

    • @StephHami
      @StephHami 4 หลายเดือนก่อน

      you have to have the latest version of unity

    • @sebastiangeraldohirales4935
      @sebastiangeraldohirales4935 3 หลายเดือนก่อน

      x2

    • @StephHami
      @StephHami 3 หลายเดือนก่อน

      @@sebastiangeraldohirales4935 ?

  • @EuclidStreams
    @EuclidStreams 2 หลายเดือนก่อน

    just use late update for camera rotation lol, wtf

  • @srydustar5754
    @srydustar5754 3 หลายเดือนก่อน +4

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

    • @exhilex
      @exhilex หลายเดือนก่อน

      Totally true