First Person Character Controller - FPS Game With Unity & Blender

Поділитися
Вставка
  • Опубліковано 7 жов 2024
  • FIRST PERSON CHARACTER CONTROLLER
    In the sixth episode of the FPS Game remake I show you how to make a first person character controller that can walk, run, jump and fall. If you want me to add crouching feel free to let me know in the comments.
    Feel free to donate if you are rich :D
    streamlabs.com...
    Thanks to: Robin Brown, Tom Taborovski and Samin Grahic for their support on Patreon.
    Discord Server - / discord
    Patreon - / singlesapling
    Twitter - / singlesaplingg
    Reddit - / singlesaplinggames
    Instagram - www.instagram....
    DeviantArt - singlesaplingg...
    Facebook - / single-sapling-games-2...
    Itch.IO - single-sapling...+
    Tumblr - / singlesapling
    UA-cam - / @singlesapling
    --Programs--
    Engine: Unity - unity3d.com/
    Modeling: Blender - www.blender.org/
    2D Editing: Krita - krita.org/en/
    Programing: Visual Studio - visualstudio.m...
    Organization: Trello - trello.com/
    --Outro Music--
    Song: Horizon (feat. Tylah Rose) - Loreno Mayer & Haesën
    Music provided by Ninety9Lives
    Video: • Loreno Mayer & Haesën ...
    Download: 99l.tv/88HorizonYU
    --TAGS--
    script make game for free 2020 development dev unity blender program tutorial guide new hd twitter youtube developer indie design art cool easy quick fast fps first person shooter game gaming how to intro introduction learn teach learning teaching livestream live stream indiegamedev indiegame indie unity2020 blender3d unity3d devlog

КОМЕНТАРІ • 76

  • @Vangsguard
    @Vangsguard 3 роки тому +59

    Problem: Player can jump multiple times
    Solution: He forgot to set the layer mask when setting isCharacterGrounded. Here is how to fix it. At 24:34 he makes this line:
    isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);
    He forgets at the end of the line after groundDistance to specify which layer it should check. This is why you jump so much. To fix it you simply use the already made LayerMask called groundMask. So the line should go from the above to the following:
    isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);
    Hope this helped!

    • @phanikumarc3ipl_branch644
      @phanikumarc3ipl_branch644 3 роки тому +1

      Yeah

    • @epicnessatpeak
      @epicnessatpeak 3 роки тому +3

      Thanks so much!!! i had trouble reading so i might add extra lines to make it cleaner.
      how to fix:
      find "isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);" in "HandleIsGrounded"
      around line 60.
      then add "groundMask" after "groundDistance" so it should end up looking like this:
      isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);

    • @mahoromatic02
      @mahoromatic02 2 роки тому +3

      Thank you man

    • @Vangsguard
      @Vangsguard 2 роки тому +1

      @@mahoromatic02 No problem. Merry christmas

    • @0sence151
      @0sence151 2 роки тому +1

      thx helped alot

  • @-HyperX-
    @-HyperX- 3 роки тому +21

    If every Unity tutorial was as good as yours, we'd all be working at Nintendo. Great job, man! Keep up the good work! 👍 The way you explain things, the encouragement you provide, and the coding practices you teach... I believe you can become the new Brackeys!

    • @SingleSapling
      @SingleSapling  3 роки тому +2

      Aw sheeet, thanks man

    • @grimreapybones2875
      @grimreapybones2875 2 роки тому +1

      Out of all the tutorials my stupid ass has watched, single sapling has the ones that I struggle with the least, I don't run into as many errors and bugs with his stuff. I can't wait to get deep into making my game, I especially can't wait to learn how to do proceederal generation, that will be fun, but probably also a nightmare

  • @5th_Vertex
    @5th_Vertex 2 роки тому +8

    Very good tutorial! Maybe you can create tutorial series like that but 3rd person? Please?

  • @grimreapybones2875
    @grimreapybones2875 2 роки тому +3

    I just want to say the organization method you use is super helpful! I have never seen anybody on UA-cam use this but I'm glad you showed me
    Because it actually helps me remember what every bit of code does since the voids names tell me what they do
    So this is super helpful for noobs like me

  • @TangoMang0
    @TangoMang0 2 роки тому +1

    These tutorials are amazing!!! Been wanting to get a start on modeling and game design once I get a break from college in the summer and this is the time. Glad I found these, this is everything I could've asked for and more. Very comprehensive and to the point, making sure to explain anything that may be ambiguous so that we can actually learn instead of just following a step by step process where we don't actually learn anything. Thank you so much for these tutorials. I have your blender shortcuts tacked on my wall above my monitor and its really nice to have. It's very nice of you to offer all of this for free, and believe me when I say that they will always be appreciated (even 9 months after posting).

  • @DawudUmar-b1v
    @DawudUmar-b1v 9 місяців тому

    I am a beginner to unity with little to some xperience, and this has helped me learn a lot about variables, vector3, floats, and so many more things. thank you so much for everything

  • @arcosic
    @arcosic Рік тому +4

    *This is a really good guide btw*
    I've noticed, and I'm not the only one, that you can jump multiple times using these scripts.
    A solution (props to @Vangsguard) is to add 'groundMask' at the end of your code.
    Example:
    (skipped out a bit of code, but you could find the code in your code)
    private float groundDistance;
    private LayerMask groundMask;
    private void HandleIsGrounded()
    {
    isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance);
    }
    (For this, add ', groundMask' to the end of the code in the brackets so that it looks like: isCharacterGrounded = Physics.CheckSphere(transform.position, groundDistance, groundMask);)
    Additionally, make sure to make the layer of any ground you have set to the same layer mask (in my case, groundMask)
    (Single Sapling goes over that in his video)
    Afterwards, you may encounter a problem that you can't jump whatsoever. However, your gravity has been made more realistic if you start at a high y level.
    A fix to this is to go into the game preview and change the 'groundDistance' variable in your inspector until the 'isCharacterGrounded' bool variable is ticked.
    If it is not ticked, you won't be able to jump.
    (IDK why this happens, as I am fairly new, but it works so eh, some programming nerd could explain it)
    Now the gravity and jumps are both realistic.
    Hope this helps someone, and if you need help, just comment on this / tag me, and I will try to respond.
    :)

    • @Iamaqwerte
      @Iamaqwerte Рік тому +2

      Thanks! You helped me out!

    • @CrazyElephant17
      @CrazyElephant17 Рік тому

      Thank you!! I changed the 'groundDistance' to 1.1 greater than my players y axis position (my case y = 1.08) after playing.

  • @silisto4223
    @silisto4223 2 роки тому +2

    One of the best Unity tutorial! Nice job

  • @Falcon_1039
    @Falcon_1039 2 роки тому

    the only tutorials ive found that actually explain what the code is doing and how its doing it, all the others are "just write this and it does this" instead of actually explaining things

  • @dilshangunawardena2717
    @dilshangunawardena2717 2 роки тому

    so far i've been learning a lot from your videos man thank you !!! 😍👍❤❤

  • @Flying_Gecko
    @Flying_Gecko 2 роки тому

    you're a great teacher, thank you for this tutorial

  • @cherylklimack325
    @cherylklimack325 Рік тому

    very good tutorial!

  • @leonardocomposiçoes
    @leonardocomposiçoes 3 роки тому +1

    good job!

  • @lcswolf
    @lcswolf 3 роки тому +4

    Great Video but wouldn't it be a good idea to use the new Input system or is it not up to sctrach? I have been trying to find a good first-person character tutorial for it for a while

    • @SingleSapling
      @SingleSapling  3 роки тому +2

      Yeah, Ive been looking for some good documentation for it so I am not using it yet, but hopefully soon

  • @osmiodebom
    @osmiodebom 3 роки тому +1

    Top

  • @siddhoot
    @siddhoot 2 роки тому

    15:42 marking my point

  • @l.1.z.a.r.d847
    @l.1.z.a.r.d847 2 роки тому +1

    as soon as i finished the jumping code, my player just keeps flying up?!?!

  • @synkgd619
    @synkgd619 2 роки тому

    with the player movement can you make the camera like bob and offset when you land from jumping or falling

  • @minithanos20
    @minithanos20 Рік тому

    You forgot groundMask in Physics.CheckSphere

  • @grimreapybones2875
    @grimreapybones2875 2 роки тому +2

    My isGrounded code does not check if my character is grounded
    Since I can still jump in the after putting it in the if statement of handle jumping
    Edit: okay fixed it, the solution was to add the ground mask variable to the handle is grounded code

    • @SingleSapling
      @SingleSapling  2 роки тому

      Check everything in the video again, really check it and then let me know if its still there

    • @grimreapybones2875
      @grimreapybones2875 2 роки тому +1

      @@SingleSapling the code is a bit quirky it seems but if I add the ground mask variable to the handle is grounded code
      Like so
      IsCharacterGroundrd = Physics.CheckSphere(transform.position, ground distance, GroundMask);
      Then it works
      So
      Yay :D

  • @nicantic2675
    @nicantic2675 2 роки тому

    my players feet dont touch the ground because when i put the arms pivot everything goes up not just the arms pivot so when i do the code to stop jumping infinitely it doesnt work because the feet are at the arms pivot and therefore never actually touches the ground. (Idk if this makes sense but all im saying is when u clikc on player it is on the ground but when i click player it is at my arms)

  • @karolstepien8213
    @karolstepien8213 10 місяців тому

    Any idea why my player doesn't want to move?

  • @sxolarbit6927
    @sxolarbit6927 3 роки тому

    At one point on my plane I start to fall through the plane. Any solutions?

  • @vexprod_1759
    @vexprod_1759 2 роки тому +1

    need help with the draging the first script part, its crashing my unity editor/unityhub

  • @rigoabell4863
    @rigoabell4863 Рік тому

    Where do you get this information from?

  • @MechTronMan
    @MechTronMan 2 роки тому

    When i drag the arm model into the empty arms object, the player position gets moved to 1.65m. Cant find a way around this

  • @prabhnoorsingh8235
    @prabhnoorsingh8235 3 роки тому +1

    Why do you make variables serialize field when you can make them public

    • @SingleSapling
      @SingleSapling  3 роки тому

      I explained at one point, serialize field is literally made for this use so...

    • @prabhnoorsingh8235
      @prabhnoorsingh8235 3 роки тому +1

      @@SingleSapling but you can make it public

    • @prabhnoorsingh8235
      @prabhnoorsingh8235 3 роки тому

      @@SingleSapling why use serialize field

    • @SingleSapling
      @SingleSapling  3 роки тому

      Sure you could, but this makes is so its not accesible by other scripts, it keeps the code clean and its just good practice all around

    • @Vangsguard
      @Vangsguard 3 роки тому +1

      @@prabhnoorsingh8235 What i understood is that its a good way of protecting scripts. Like when people exploit so you cant access it from other scripts or change it. Thats why its private, and he add SerializeField to still be able to change the variables in the editor. Hope this explained why :D

  • @simoouss7100
    @simoouss7100 2 роки тому +1

    i found a better way to implement the sprinting with smooth transition you just have to make another variable name it accelaration (or whatever)
    and change the two if functions with this
    if(Input.GetKey(KeyCode.LeftShift))
    {
    moveSpeed = Mathf.Lerp(moveSpeed, Runspeed, Sprint_Acceleration * Time.deltaTime);
    }else{
    moveSpeed = Mathf.Lerp(moveSpeed, Walkspeed, Sprint_Acceleration * Time.deltaTime);
    }

  • @xand10landia2
    @xand10landia2 2 роки тому

    i haver a problem. when i add groundMask i cant jump but when i remove it i can infinite jump. Any solutions?

    • @SingleSapling
      @SingleSapling  2 роки тому

      In the inspector, does the isGrounded variable in the script change at all?

  • @eginger114
    @eginger114 2 роки тому

    why do the feet go to my arms when i add them into the hierarchy?

  • @Coverllyncho
    @Coverllyncho 3 роки тому

    The feet pivot is moving in I add the low poly arms :c

    • @HumanDoing
      @HumanDoing 2 роки тому +1

      I have the same problem, any solutions?

    • @HumanDoing
      @HumanDoing 2 роки тому +3

      If anyone in the future has the same problem, this was Single Saplings anwer that worked for me:
      Does changing the transform point from Center to Pivot help? In the top left, right next to the tools

    • @Coverllyncho
      @Coverllyncho 2 роки тому

      @@HumanDoing nice I'll try it

  • @prabhnoorsingh8235
    @prabhnoorsingh8235 3 роки тому +1

    Can I use Rigidbody for fps controller

    • @SingleSapling
      @SingleSapling  3 роки тому

      U can but that is significantly harder to do

  • @nikallout5444
    @nikallout5444 3 роки тому +2

    quick tip: for running you could just use moveSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed

    • @SingleSapling
      @SingleSapling  3 роки тому +6

      Indeed that would be much cleaner. This tutorial obviously isnt for you my man you too smart, this is for beginners