Third Person Shooter (Unity Tutorial) Ep 1 Movement and Camera

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

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

  • @gaddgames
    @gaddgames  2 ปีที่แล้ว +30

    where we run controller.Move(dir * moveSpeed * Time.deltaTime); change the dir to dir.normalized to stop the character walking faster in diagonal directions
    Also in the AimStateManager class I assumed the xAxis and yAxis.Update(Time.deltaTime) would be frame rate independent, this is not the case…
    To fix this simply change these variables to floats which can be private and also add a [SerializeField] float mouseSense;
    In the Update function replace the xAxis and yAxis.Update code with
    xAxis +=(Input.GetAxisRaw(“Mouse X”) * mouseSense);
    yAxis -=(Input.GetAxisRaw(“Mouse Y”) * mouseSense);
    yAxis = Mathf.Clamp(yAxis,-80,80)
    The rest of the code will stay the same

    • @dantie7186
      @dantie7186 2 ปีที่แล้ว +1

      When I tried to change xAxis and yAxis in the update, I was told that I couldn't convert Cinemachine. AxisState to float because I was new to it and didn't quite understand it

    • @dantie7186
      @dantie7186 2 ปีที่แล้ว

      If there is project source code, can you package it and send it to me for study? Thank you for a long time

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +4

      @@dantie7186 drive.google.com/file/d/1C2LoLNtjQWVlKYYnEhN7RT9QSTvQRNjH/view
      Here is the project files for Ep 5 also in the second episode I show where I change the axis states to floats
      discord.gg/FGnPBHHQsZ here’s my discord if u need any help still

    • @mrfun3340
      @mrfun3340 2 ปีที่แล้ว +1

      You can use Vector3.ClampMagnitude(dir, 1.0f)
      instead of dir.normalized
      cuz you will get some weird movement with dir.normalized

    • @eichel32
      @eichel32 2 ปีที่แล้ว

      @@mrfun3340 thanks mate, this is what im looking for. i was using dir.normalized and it makes my player like walking on the ice

  • @mustafavurucu4944
    @mustafavurucu4944 ปีที่แล้ว +10

    This is the best tutorial i ve ever seen!! Thank you man for this serie!!!

    • @gaddgames
      @gaddgames  ปีที่แล้ว +1

      Thank you so much!

  • @oZzWoLd2198
    @oZzWoLd2198 2 ปีที่แล้ว +11

    Honestly mate I've been trying to get my own movement script and follow cam set up for like week now (I only started Unity 3 weeks ago and completely new to scripting) I've watched loaaads of youtube tuts and its either been too confusing or somethings messed up, whatever but this is literally the first video that I've been able to follow start to finish and actually understood what I've done by the end of it. Big thank you for these videos, subbed my guy.

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +2

      Much love brother 🤙

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +2

      These comments keep me going ❤️‍🔥

  • @marvindizon4917
    @marvindizon4917 2 ปีที่แล้ว +6

    This is one of the best and the latest please continue tutorial! Thank you Gadd Games!

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +4

      Thank you very much the next episode will be out today or tomorrow but was delayed because I was recording the wrong screen 🤦‍♂️

  • @gaddgames
    @gaddgames  2 ปีที่แล้ว +13

    I will cover jumping in the third video but if all you want is a simple character controller simply add a variable for jumpForce and in the update you can paste this code:
    if(IsGrounded()&&Input.getKeyDown(KeyCode.Space)) velocity.y += jumpForce;

    • @rainbowroad
      @rainbowroad ปีที่แล้ว

      also set the jumpforce to be a serialized variable so yoiu can tweak it in game

  • @patricki1422
    @patricki1422 7 หลายเดือนก่อน +1

    Better than any tutorials i've seen! You're a legend!

    • @gaddgames
      @gaddgames  7 หลายเดือนก่อน +1

      Thank you very much brother I am working on episode 17 as we speak

  • @Holf.6
    @Holf.6 2 วันที่ผ่านมา

    Brilliant, there is no tutorial like this one.
    All thins are well explained.

  • @aswinbaskaran607
    @aswinbaskaran607 2 ปีที่แล้ว +7

    I'm following your tutorial for my open world game ! Excellent job -Thanks for segregation into chapters.

  • @catboyrepublican2520
    @catboyrepublican2520 2 ปีที่แล้ว +8

    8:00 Just want to add, I've heard it's not good practice to have multiple CharacterController.Move calls in a single update loop as it could potentially cause some instability issues (plus it's really easy to fix). So my solution is to remove the move call from GetDirectionAndMove and Gravity, the in the Update loop after both those methods are called, create a Vector3 finalMove which is the sum of dir * moveSpeed and velocity, then call controller.Move(finalMove * Time.deltaTime)

  • @paulberry3359
    @paulberry3359 2 ปีที่แล้ว +2

    Really enjoyed this first video, definitely would like this to flesh out into an entire series for a in depth Third Person Shooter Character. Subbed

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      Thank you, episode 5 will be out later today and a lot of people seem to be enjoying it so I will be continuing to add things like enemy AI and a full gameplay loop by the end.

  • @honda02134
    @honda02134 ปีที่แล้ว +1

    You the best man explaining every single things

  • @48LOF
    @48LOF 8 หลายเดือนก่อน +2

    should continue this to another playlist .. very good content thank you , big help !

    • @gaddgames
      @gaddgames  7 หลายเดือนก่อน +1

      turn on the bell new videos coming soon, also I will be dropping the custom wheel collider and car controller asset for free and at some point will be adding cars to the project

  • @brosauce2814
    @brosauce2814 11 หลายเดือนก่อน +2

    Hey, Really helpful video. Quick question, how would i disable mouse acceleration? it seems to be activated.

  • @wafwghwef4weag
    @wafwghwef4weag 2 ปีที่แล้ว +3

    Thanks your tutorials are the best

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      Thank you 🙏

  • @mmar5896
    @mmar5896 8 หลายเดือนก่อน +1

    Great tutorial man

  • @Duck_editz
    @Duck_editz 11 หลายเดือนก่อน +1

    im getting the error ArgumentException: Input Axis vertical is not setup and also the error:NullreferenceException: object reference not set to an instance of an object movementstatemanager.OnDrawGizmos() how do you fix these?? also this is for the movementstatemanager script

  • @blazexy5657
    @blazexy5657 9 หลายเดือนก่อน +1

    The camera part didn't work until I moved the main cam in the camera follow

  • @jesusbazaldua8651
    @jesusbazaldua8651 9 หลายเดือนก่อน +2

    Super beginner question but how does he actually make it move was there a separate video for bindings? Is it with a controller or keyboard am lost honestly

    • @gaddgames
      @gaddgames  7 หลายเดือนก่อน +1

      So Unity has basic inputs pre set up so the Horizontal and Vertical axis for the keyboard and mouse are there for you to use and change as you wish. hope this answers your question :)

  • @cavemangamer9252
    @cavemangamer9252 2 ปีที่แล้ว +2

    Thank you I am just starting

  • @simonlu5141
    @simonlu5141 2 ปีที่แล้ว +2

    oh my oh my! a new channel about Unity! Goodie!! thank you for the videos. Subscribe!!

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Thank you 🙏

  • @BoxocronFilms
    @BoxocronFilms 7 หลายเดือนก่อน +1

    About the MovementStateManager, what software are you using for the scripting because for me it brought me to MS Word

    • @FlshChrnl
      @FlshChrnl 7 หลายเดือนก่อน +1

      Microsoft Visual Studio

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

      I am using visual studio 2022 currently I believe in this video it was the 2019 version but either will work but id recommend 2022 as it is the latest

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

    Do you have an updated AimStateManager Script for newer Cinemachine updates? I've been loving this tutorial but running into some issues particularly with the Axis. I put in the script you have (With changes "using Unity.Cinemachine;" instead of "using Cinemachine;) but AxisState is deprecated. I tried changing AxisState to InputAxis and get some errors I cant seem to get around. If I try to continue using the script as is, it still runs but when I run the game where you are at 14:08, x axis seems to work fine and the camera follows the mouse left to right but y axis doesnt seem to be registering. no up and down camera movement with all the same scripts as the vid. Are there any updates/fixes for this stuff? Thanks.

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

    Can you help solve this error ? i dont know why but no error with 'Walk' and 'Crouch' and i stuck here.
    Error:
    \States\IdleState.cs(16,79): error CS1061: 'MovementStateManager' does not contain a definition for 'Run' and no accessible extension method 'Run' accepting a first argument of type 'MovementStateManager' could be found (are you missing a using directive or an assembly reference?)

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

      Make sure the variable or the RunState Class in the movement state manager is of type MovementBaseState. It seems like you may have it as a MovementStateManager class

    • @ThaiPham-lw9um
      @ThaiPham-lw9um 4 หลายเดือนก่อน

      @@gaddgames Omg, it's my fault while coding, i typed "public RunState Rn"

  • @TheHatsDude
    @TheHatsDude ปีที่แล้ว +1

    Hi, i followed all the instructions but i think is the new input system. Look when i put everything and go to check i have a problem that says : Cannot modify the return value of 'Transform.position' because it is not a variable
    Please i need help. :(

    • @gaddgames
      @gaddgames  ปีที่แล้ว +2

      You need transform with a lower case t

  • @H1D3_15
    @H1D3_15 2 ปีที่แล้ว +1

    i love this man holy

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

    Looks great. I plan to follow this tutorial but make a movable character for unity mobile (Coz I don't want to follow some tutorial deto copy and want to do some of the stuff myself. That's why choosing a different platform). Any advice you wanna give before I start following this series?

  • @LFC_DCB
    @LFC_DCB 9 หลายเดือนก่อน +1

    I did everything right but for some reason, I can't move my camera around whenever im moving the player but the player does move in the camera forward. How do i fix this

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

      Do you still need any help brother?

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

      @@gaddgames guess he doesnt need any help now

  • @gabrielfavaro2665
    @gabrielfavaro2665 2 ปีที่แล้ว +1

    tip, use GetAxisRaw for a more responsive movement

  • @RafaelFernandesKingRafa
    @RafaelFernandesKingRafa 2 ปีที่แล้ว +1

    Incrível esse tutorial, funcionou de primeiro mesmo tendo o básico em inglês foi o melhor tutorial de todos, continue assim, está de parabéns

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Merci beaucoup monsieur!

  • @Jul3kit
    @Jul3kit 8 หลายเดือนก่อน +1

    What application did you use for the movement state manager? I can't open it because I don't have a compatible app

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

      I use visual studio 2022 at the moment sorry for the late response, keep it up buddy

  • @therealmasterluke407
    @therealmasterluke407 10 หลายเดือนก่อน +1

    can help me fix the issue that when evry time i click play its says compile errors need to be fixed or something anyways great tutorial!

  • @alleyesonme1432
    @alleyesonme1432 2 ปีที่แล้ว +2

    Great job

  • @MartyinVirtualReality
    @MartyinVirtualReality 2 ปีที่แล้ว +1

    Crazy beginner question. I'm starting with this video and Googling loads at every step. After creating the Movement State Manager script your screen goes to the place you can type code. What coding program is that?

    • @MartyinVirtualReality
      @MartyinVirtualReality 2 ปีที่แล้ว +1

      Scratch that, I figured it out from another TH-cam video. But I'll keep the comment for the algo, if that helps? Thanks for the content!

    • @edwardgraham184
      @edwardgraham184 ปีที่แล้ว +1

      @@MartyinVirtualReality Incase anyone else doesn't know its Microsoft visual studio.

  • @tazz1226
    @tazz1226 27 วันที่ผ่านมา

    Why would u do gravity inside the player object? Seems not scalable, the engine got its own way of dealing with this.

  • @mr.giray1542
    @mr.giray1542 ปีที่แล้ว +1

    no matter what ı do it drops so fast what do ı do ?

  • @พีรันธร
    @พีรันธร หลายเดือนก่อน

    Have specific option? I use alot of camera but I need just one to aim camera other just Free look

  • @oggvs4
    @oggvs4 2 วันที่ผ่านมา

    Hi, when i typed vInput, it sayed "the name vInput does not exist in current context can anyone help me?

  • @Amarxkmane
    @Amarxkmane 2 ปีที่แล้ว +1

    Thank you so much bro!

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      Happy to help!

  • @7y700-s1u
    @7y700-s1u ปีที่แล้ว

    Whenever I add the ground layer and set the layer mask to it, my capsule still snaps/falls really fast. Has anyone else had this issue? Im on a slightly newer version of unity 2022.3.8

  • @romankovalevich196
    @romankovalevich196 2 ปีที่แล้ว

    Tell me where I could have messed up, everything works for me, only the inversion on the y axis, when I move the mouse up, the character looks down and vice versa

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

    here in this if we want that camera is alwys in d back side of character and follows character when on swipe we change camera angle than character angle must be same as camera...how this possible?

  • @nicolasportu
    @nicolasportu 2 ปีที่แล้ว +1

    Outstanding!

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Glad you like it!

  • @foreignyard1720
    @foreignyard1720 ปีที่แล้ว

    Bro Great Video thank you so much,
    How did you get a deep knowledge of c#, and do you have a Discord?

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

    If I used someone else character controller script then what do I need to change to follow along with your next tutorials?

  • @clarkmeyer7211
    @clarkmeyer7211 2 ปีที่แล้ว

    very cool. easy to follow.

  • @botaniccanon1596
    @botaniccanon1596 6 หลายเดือนก่อน +1

    Kool TPS Controller Could I use for commercial use?

    • @gaddgames
      @gaddgames  6 หลายเดือนก่อน +1

      Sure thing I quit my job yesterday so even more episodes coming soon

  • @GamerGaruud
    @GamerGaruud 8 หลายเดือนก่อน +1

    nothing is happening when I move my mouse around pls help

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

      Have you fixed this issue yet? If not send me a message on discord

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

      @@gaddgames I ended up with a brackeys video...dunno how but a code line solved it apparently lol

  • @shadowartz9968
    @shadowartz9968 ปีที่แล้ว

    Is there a way to make the character rotate only after the camera reaches a certain angle? Trying to recreate Transformers fall of cybertron controls or like Minecraft 3rd person where your player rotates after a certain point

  • @MuborRemix
    @MuborRemix 7 หลายเดือนก่อน +1

    Thanks u, my bro!!!!

    • @gaddgames
      @gaddgames  7 หลายเดือนก่อน +1

      Thank you too!

  • @IJH-Music
    @IJH-Music 2 ปีที่แล้ว +1

    Great tutorial!
    Use some compression/limiting for your audio. You are very quiet!

  • @itss_deluxevv
    @itss_deluxevv ปีที่แล้ว

    please help me I keep on getting an error saying that the variable controller for movement state manager has not been assigned. I'm a beginner and I don't know how to solve this on my own and it wont let me play the game until I fix it. Please help!!!

  • @Nvdtpu
    @Nvdtpu ปีที่แล้ว

    i keep getting the error Assets\MovementStateManager.cs(8,6): error CS0246: The type or namespace name 'hideinspectorAttribute' could not be found (are you missing a using directive or an assembly reference?) what to do?

  • @prod.cap0
    @prod.cap0 2 ปีที่แล้ว

    i typed in everything that was given to me and i keep getting the same 3 errors. someone please help😭
    edit; nvm i was able to get rid of them but got a new one. error cs0103L the name 'controller' does not exist in the current conect
    when should i do?

  • @sahilgangurde4886
    @sahilgangurde4886 ปีที่แล้ว

    my mouse working opposite when i drag up camera faces down and vice versa any solution ??

    • @gaddgames
      @gaddgames  ปีที่แล้ว

      Make sure you invert the input by putting a - behind where you capture the vertical input from the mouse

  • @SpaceIndie
    @SpaceIndie 2 ปีที่แล้ว

    I followed your code for the Cinemachine, but it didn't pop up with the menu it did for you?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      In the next video the axis states get replaced anyway lol

  • @Joe_Rogan_Clips_21
    @Joe_Rogan_Clips_21 9 หลายเดือนก่อน +1

    This guy is so smart

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

      My friends would disagree :D

  • @mr.bill4752
    @mr.bill4752 ปีที่แล้ว

    Anyone know how to controlee the CM virtual camera here with input from actionMap of new input system?

    • @IJH-Music
      @IJH-Music ปีที่แล้ว

      Have you found out how? I'm not sure how to, and I need help.

  • @zaalty2795
    @zaalty2795 ปีที่แล้ว

    the camera always stays in the center of the screen it doesn't follow the player the code is correct i don't know why it doesn't work

  • @leartmena6845
    @leartmena6845 ปีที่แล้ว

    Bro I'm unable to use Mouse X and Y. I did every step that you did but it dont work. please if you have any idea what i could do pleaaaasee say it to me. thanks

    • @gaddgames
      @gaddgames  ปีที่แล้ว

      Watch the second video it gets changed anyway

    • @leartmena6845
      @leartmena6845 ปีที่แล้ว

      @@gaddgames thanks mate

  • @DarthSerul
    @DarthSerul 2 ปีที่แล้ว +1

    Thank you!!

  • @Davidgotbored
    @Davidgotbored 2 ปีที่แล้ว

    i keep on getting errors that say Assets\MovementStateManager.cs(7,29): error CS1519: Invalid token '=' in class, record, struct, or interface member declaration

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

      It can be you unity version

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

      @@Thatonegamers11459 oh ok thanks I gave up like a year ago but that could be a good tip

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

      @@Thatonegamers11459 so I’ll try again

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

      @@Davidgotbored 🤣🤣 sorry

  • @Youraveragefnplayer
    @Youraveragefnplayer 11 หลายเดือนก่อน +1

    The code doesnt work for me (movement)

    • @ThePirates-id2qo
      @ThePirates-id2qo 11 หลายเดือนก่อน +1

      look if you did a type

  • @InvixYT
    @InvixYT 2 ปีที่แล้ว

    You don't even have to make a ground check. The Unity CharacterController has it's build in controller.isGrounded. You can just check that with an if statement and handle the rest of the logic in there.

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      I didn’t know this but I did it the way I did it to make sure you can’t infinite jump up walls

  • @MaximCemencov
    @MaximCemencov 2 ปีที่แล้ว +1

    Gadd Games are you planning to create your own discord server?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Discord link is somewhere on my TH-cam banner

  • @hanadanefa7837
    @hanadanefa7837 2 ปีที่แล้ว

    don't you have tutorial just like this series where you use the new input system?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      I’m tempted to make a video on how to upgrade this project to the new Input system. But will probably continue the series with the old system due to simplicity

  • @leonardocomposiçoes
    @leonardocomposiçoes ปีที่แล้ว

    create fps multiplayer series tutorial using photon pun 2 and mixamo animations please!

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

    Camera script doesn't work with Unity 6 at all, but good tutorial after all.

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

      Thank you for reminding me I picked Unity back up after a few months break and saw they had a Unity 6 so I upgraded the project and realised the same thing so I will have to make a new video for the cinemachine update

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

      @@gaddgames is there a new video for this i am losing my mind bc of this change unity made. Amazing work btw ty so much !!

  • @giddyhaddcock_gaming5396
    @giddyhaddcock_gaming5396 9 หลายเดือนก่อน +1

    everything works ok apart from the movement it doesn't go in proper direction

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

      That was my mums favourite part of the video, in the future I am going to edit it less so I will show that I am no genius and it takes time, effort and persistence. I am still learning and always will be

  • @why9265
    @why9265 ปีที่แล้ว

    Hey Gadd, I followed every step of this video exactly but the character doesn't stop moving for a few more seconds even after I took my hands off the controls.
    Here's the code(If there's something that I did wrong, please tell me!):
    MovementStateManager.cs
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class MovementStateManager : MonoBehaviour
    {
    public float movespeed = 3;
    float hzInput, vInput;
    [HideInInspector] public Vector3 dir;
    CharacterController controller;
    [SerializeField] float groundYOffset;
    [SerializeField] LayerMask groundMask;
    Vector3 spherePos;
    [SerializeField] float gravity = -9.81f;
    Vector3 velocity;
    void Start()
    {
    controller = GetComponent();
    }
    void Update()
    {
    GetDirectionAndMove();
    Gravity();
    }
    void GetDirectionAndMove()
    {
    hzInput = Input.GetAxis("Horizontal");
    vInput = Input.GetAxis("Vertical");
    dir = transform.forward * vInput + transform.right * hzInput;
    controller.Move(dir.normalized * movespeed * Time.deltaTime);
    }
    bool IsGrounded()
    {
    spherePos = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
    if (Physics.CheckSphere(spherePos, controller.radius - 0.05f, groundMask)) return true;
    return false;
    }
    void Gravity()
    {
    if (!IsGrounded()) velocity.y += gravity * Time.deltaTime;
    else if (velocity.y < 0) velocity.y = -2;
    controller.Move(velocity * Time.deltaTime);
    }
    private void OnDrawGizmos()
    {
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(spherePos, controller.radius - 0.05f);
    }
    }

    • @Dominicn123
      @Dominicn123 ปีที่แล้ว

      anneyong, try this bro:
      public class MovementStateManager : MonoBehaviour
      {
      #region Movement
      public float currentMoveSpeed;
      public float walkSpeed = 1, walkBackSpeed = 1;
      public float runSpeed = 3, runBackSpeed = 3;
      public float crouchSpeed = 2, crouchBackSpeed = 1;
      [HideInInspector] public Vector3 dir;
      [HideInInspector] public float hzInput, vInput;
      CharacterController controller;
      #endregion
      [SerializeField]float groundYOffset;
      [SerializeField] LayerMask groundMask;
      Vector3 spherePos;
      [SerializeField] float gravity = -9.81f;
      Vector3 velocity;
      MovementBaseState currentState;
      public IdleState Idle = new IdleState();
      public WalkState Walk = new WalkState();
      public CrouchState Crouch = new CrouchState();
      public RunState Run = new RunState();
      [HideInInspector] public Animator anim;
      // Start is called before the first frame update
      void Start()
      {
      anim = GetComponentInChildren();
      controller = GetComponent();
      SwitchState(Idle);
      }
      // Update is called once per frame
      void Update()
      {
      GetDirectionAndMove();
      Gravity();
      anim.SetFloat("hzInput", hzInput);
      anim.SetFloat("vInput", vInput);
      currentState.UpdateState(this);
      }
      public void SwitchState(MovementBaseState state)
      {
      currentState = state;
      currentState.EnterState(this);
      }
      void GetDirectionAndMove()
      {
      hzInput = Input.GetAxis("Horizontal");
      vInput = Input.GetAxis("Vertical");
      dir = transform.forward * vInput + transform.right * hzInput;
      controller.Move(dir.normalized * currentMoveSpeed * Time.deltaTime);
      }
      bool IsGrounded()
      {
      spherePos = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
      if (Physics.CheckSphere(spherePos, controller.radius - 0.05f, groundMask)) return true;
      return false;
      }
      void Gravity()
      {
      if(!IsGrounded()) velocity.y += gravity * Time.deltaTime;
      else if (velocity.y < 0) velocity.y = -2;
      controller.Move(velocity * Time.deltaTime);
      }
      private void OnDrawGizmos()
      {
      Gizmos.color = Color.red;
      Gizmos.DrawWireSphere(spherePos, controller.radius - 0.05f);
      }
      }

    • @why9265
      @why9265 ปีที่แล้ว

      @@Dominicn123 Thanks for the help! I really appreciate it!

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

    I HAVE A 22 COMPILLER ERRORS🤧🤧🤧
    Can someone sent a working code pls?

  • @Franklinsbrother
    @Franklinsbrother ปีที่แล้ว +2

    Yet another tutorial that doesn't work (probably due to Unity's constant annoying updates). It wouldn't let me add a CineMachine Virtual Camera unless I parented it to an object on the hierarchy and it's symbol doesn't appear next to the main camera and it doesn't function. I'm so sick of unity's bullcrap.

    • @gaddgames
      @gaddgames  ปีที่แล้ว +3

      I’ll have a look into it and see if I can find a fix for you

    • @Franklinsbrother
      @Franklinsbrother ปีที่แล้ว +1

      @@gaddgames Never Mind, I got it to work! For some reason, if I selected it in the Component Tab from the tab, it would be grayed out and not selectable unless I parented it to an object in the hierarchy, in which case it wouldn't work. However, when I right-clicked the Hierarchy and selected Cinemachine and virtual camera from there, it worked just as you showed. Thank you for your attempted support regardless!

  • @Gli_sck
    @Gli_sck 2 ปีที่แล้ว

    why the MonoBehaviour is white and not blue? same for other things they are white not grey

    • @Gli_sck
      @Gli_sck 2 ปีที่แล้ว

      asking bc the script isnt working without these

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      If you go on Unity and click file/project settings/ external tools. Do you have your IDE selected in the drop down?

    • @Gli_sck
      @Gli_sck 2 ปีที่แล้ว

      @@gaddgames wait unity hub or the project?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      @@Gli_sck when your in the project. If you still need help send me a message on discord and I can help you get it sorted

    • @Gli_sck
      @Gli_sck 2 ปีที่แล้ว +1

      @@gaddgames oh i discovered how to fix that, thanks for replying you're a very good youtuber:)

  • @H1D3_15
    @H1D3_15 2 ปีที่แล้ว +1

    i got some error that said:
    nullreferenceException: object reference not set to an instance of an object movementStateManager.OnDrawGizmos
    can someone help me

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      Run the game and it will go away and when you have set it up just comment out the code and it will go away

  • @sypnes
    @sypnes 2 ปีที่แล้ว

    hide in inspector not visible help me sir

  • @am7_992
    @am7_992 ปีที่แล้ว

    Does this tutorial work for FPS game?

  • @samarth6937
    @samarth6937 ปีที่แล้ว

    It tells '*' cannot be used for vector3

    • @samarth6937
      @samarth6937 ปีที่แล้ว

      In the first script

  • @ZotaEdits
    @ZotaEdits 2 ปีที่แล้ว

    Theres something wrog with my code please help ive reviewed it so many times

  • @clarkmeyer7211
    @clarkmeyer7211 2 ปีที่แล้ว

    public float moveSpeed = 3f;
    [HideInInspector] public Vector3 dir;
    float hzInput, vInput;
    CharacterController controller;
    [SerializedField] float groundYOffset;
    [SerializedField] LayerMask groundMask;
    Vector3 spherePos;
    [SerializedField] float gravity =-9.81f;
    Vector3 velocity;
    only moveSpeed is showing in inspector. why?????

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      Serialize instead of Serialized

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Go to file at the top left of Unity then preferences/ external tools, then select your IDE from the drop down menu then regenerate project files then it should make things easier to follow along with

    • @clarkmeyer7211
      @clarkmeyer7211 2 ปีที่แล้ว

      @@gaddgames oh shit. lmfao thank you. Can't believe I did that. its My intellisense that seems to be screwing me over and I didn't look properly

    • @clarkmeyer7211
      @clarkmeyer7211 2 ปีที่แล้ว

      @@gaddgames I did that now. its not that. there is something wrong with the assemblies not showing up for me for some reason. I had a fix for it but that doesn't seem to be an option for me sadly. do you have a discord?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Yeah there is a link to it on my channel banner thing

  • @e-brosanimations231
    @e-brosanimations231 ปีที่แล้ว +1

    I am 117th comment...
    MISTER CHEF

  • @macatacwarrior7204
    @macatacwarrior7204 ปีที่แล้ว

    how does one add jumping

    • @gaddgames
      @gaddgames  ปีที่แล้ว +1

      By carry on watching the series

  • @beanie.weanie
    @beanie.weanie 11 หลายเดือนก่อน

    What do you use for the code?

    • @ThePirates-id2qo
      @ThePirates-id2qo 11 หลายเดือนก่อน

      vs code

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

      I’m using visual studio 2022 in this video

  • @nbdsnipez5403
    @nbdsnipez5403 2 ปีที่แล้ว

    hello im becoming an indie developer is it possible to change the model with my own?

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Yes you can in the second episode which is out now I show you how to replace the model with the capsule and get the animations set up. Finally in the third episode I will be showing you how to write the code to change the animations depending if you are running, crouching or walking. If you have any questions feel free to message me on my discord which you can find on my website gadd.games

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      The discord link is in my links page on my website also make sure to read the pinned comments on this video. Thank you for watching!

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

    cant get the jumping workinng

  • @ahmetsatukbugrademirel2877
    @ahmetsatukbugrademirel2877 9 หลายเดือนก่อน +1

    king king u are a king amk !!!!!!

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

      I'm but a mere peasant good sir

  • @therealhecker
    @therealhecker 2 ปีที่แล้ว

    is this series suitable for beginners

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      I wouldn’t recommend for absolute beginners but definitely with a basic knowledge of unity you could follow along

    • @therealhecker
      @therealhecker 2 ปีที่แล้ว

      @@gaddgames iam a absolute beginner which series shopuld i watch for unity (other than brackeys )i like to learn 3d stuff not 2d games

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว +1

      What I did to start learning was the create with code course on the Unity learn website was very helpful and simple to understand

  • @huhigames5393
    @huhigames5393 9 วันที่ผ่านมา

    i dont know if it is just me but rotation is very laggy

  • @nathandobbyn8747
    @nathandobbyn8747 2 ปีที่แล้ว

    Thanks for the tutorial, btw, i use rigidbody, so i can't follow 3/4 of the tutorial :(

    • @gaddgames
      @gaddgames  2 ปีที่แล้ว

      Might have to make a rigid body movement tutorial 🤔

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

    Aus spaß macht sowas keiner kein verbrechen ohne das man was verdient !

  • @cybermeso3412
    @cybermeso3412 ปีที่แล้ว

    What language is he using

  • @kriande
    @kriande ปีที่แล้ว

    Why do you not use rigibody??

  • @systemkey1
    @systemkey1 5 หลายเดือนก่อน +1

    why does unity take fucking forever to do anything

  • @GamingTimesForever
    @GamingTimesForever 9 หลายเดือนก่อน +1

    kam ni kitta :(

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

      何が問題ですか

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

    When im testing

  • @sohanrai3850
    @sohanrai3850 12 วันที่ผ่านมา

    AimStateManager:
    using UnityEngine;
    using Unity.Cinemachine;
    using UnityEngine.InputSystem;
    public class AimStateManager : MonoBehaviour
    {
    [SerializeField] private Transform camFollowPos;
    [SerializeField] private float mouseSensitivity = 1f;
    private float xRotation;
    private float yRotation;
    private PlayerInput playerInput;
    private InputAction lookAction;
    private void Start()
    {
    // Set up input
    playerInput = GetComponent();
    if (playerInput != null)
    {
    lookAction = playerInput.actions["Look"];
    lookAction?.Enable();
    }
    // Lock cursor
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }
    private void OnDisable()
    {
    lookAction?.Disable();
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    }
    private void Update()
    {
    if (lookAction != null)
    {
    // Get input from new Input System
    Vector2 lookDelta = lookAction.ReadValue();
    // Apply sensitivity
    xRotation += lookDelta.x * mouseSensitivity;
    yRotation -= lookDelta.y * mouseSensitivity;
    // Clamp vertical rotation
    yRotation = Mathf.Clamp(yRotation, -80f, 80f);
    }
    }
    private void LateUpdate()
    {
    if (camFollowPos != null)
    {
    // Apply rotations
    camFollowPos.localEulerAngles = new Vector3(yRotation, camFollowPos.localEulerAngles.y, camFollowPos.localEulerAngles.z);
    transform.eulerAngles = new Vector3(transform.eulerAngles.x, xRotation, transform.eulerAngles.z);
    }
    }
    }
    ---------------------------------------------------------------------------------------------------------------
    MovementStateManager:
    using UnityEngine;
    public class MovementStateManager : MonoBehaviour
    {
    [SerializeField] private float moveSpeed = 3f;
    [SerializeField] private float groundYOffset = 0.1f;
    [SerializeField] private LayerMask groundMask;
    [SerializeField] private float gravity = -9.81f;
    private CharacterController controller;
    private Vector3 velocity;
    private Vector3 movementDirection;
    private Vector3 spherePosition;
    private void Awake()
    {
    // Cache the CharacterController component for performance
    controller = GetComponent();
    if (controller == null)
    {
    Debug.LogError("CharacterController component is missing!");
    enabled = false;
    return;
    }
    }
    private void Update()
    {
    // Calculate movement direction
    GetDirection();
    // Apply gravity
    ApplyGravity();
    // Combine movement and gravity, then move the character
    Vector3 finalMove = movementDirection * moveSpeed + velocity;
    controller.Move(finalMove * Time.deltaTime);
    }
    private void GetDirection()
    {
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");
    movementDirection = transform.forward * verticalInput + transform.right * horizontalInput;
    }
    private bool IsGrounded()
    {
    spherePosition = new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z);
    return Physics.CheckSphere(spherePosition, controller.radius - 0.05f, groundMask);
    }
    private void ApplyGravity()
    {
    if (IsGrounded())
    {
    // Reset gravity when grounded
    if (velocity.y < 0)
    {
    velocity.y = -2f; // Slight negative value to ensure contact with the ground
    }
    }
    else
    {
    // Apply gravity over time when not grounded
    velocity.y += gravity * Time.deltaTime;
    }
    }
    private void OnDrawGizmos()
    {
    // Visualize the ground check sphere in the Scene view
    Gizmos.color = Color.red;
    Gizmos.DrawWireSphere(
    new Vector3(transform.position.x, transform.position.y - groundYOffset, transform.position.z),
    controller != null ? controller.radius - 0.05f : 0.5f
    );
    }
    }

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

    6 Jahre Bau wenn du in ein fremdes netzwerkt eindringst !! :)

  • @BlueSky-bz9vn
    @BlueSky-bz9vn ปีที่แล้ว

    This video is not for beginner

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

    My character is not moving

  • @jonauthor1813
    @jonauthor1813 ปีที่แล้ว +1

    I dont understand why ur voice is low please before making any tutorial at least check your sound

  • @aaronhernandez5965
    @aaronhernandez5965 2 ปีที่แล้ว

    NullReferenceException: Object reference not set to an instance of an object
    MovementStateManagement.OnDrawGizmos () (at Assets/MovementStateManagement.cs:60)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) i have this problem how i can fix

    • @akshat6174
      @akshat6174 ปีที่แล้ว

      did you get this fixed? pls help a fellow out if so

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

    ay man im stuck at 14:00 i cant play bc it automaticly pauses the game and when i try to unpause it gives me an error saying: System.ArgumentException: Input Axis Mouse Y is not setup. can you help me out please?

    • @Kapsuva81165
      @Kapsuva81165 6 หลายเดือนก่อน +1

      nwm did it myself lol

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

      @Kapsuva81165 good job 😁