Godot Advanced FPS Movement - Crouching Tutorial In 5 Minutes

Поділитися
Вставка
  • Опубліковано 30 лип 2024
  • -- Social --
    Discord: the discord server has been shut down, sorry!
    Twitter: / garbaj2
    -- Links --
    Github: github.com/GarbajYT
    -- About --
    Following up on our basic first person shooter character controller tutorial, this video will be the first installment in a new advanced FPS movement series where we dive deeper into more complex movement mechanics. In this video, I'll be showing you how to make your FPS character crouch. A simple ability that is not so simple to implement.
  • Ігри

КОМЕНТАРІ • 119

  • @IrvanQadri
    @IrvanQadri 4 роки тому +68

    username: garbaj
    video quality: not garbaj

    • @garbaj
      @garbaj  4 роки тому +8

      Hehe, thanks

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

      Saw that myself - name is Lol quality is O.O
      Agreed.

  • @Fafhrd42
    @Fafhrd42 2 роки тому +12

    An alternative approach for crouching that some may find useful: Set the default height of the capsule to be the crouched height, and then make the head a collision sphere with the same radius as the capsule instead of a Spatial node. Then you just have to move the head down enough that the sphere will be inside the capsule when you crouch. There should still be enough overlap when standing that you won't have gaps between the head and body that bullets can pass through. And as an added bonus you'll essentially get headshot detection for free, since the head will already have its own collision.

  • @morkmon
    @morkmon 3 роки тому +25

    btw: for the sticking to the ceiling problem you can actually use the _KinematicBody_ _is_on_ceiling()_ method that works the same as _is_on_floor()_ but, you guessed it, for ceilings.

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

      Thanks for the tip!

    • @morkmon
      @morkmon 3 роки тому +5

      @@garbaj you thanks for the excellent tutorials, they are just what I needed to get started with godot!

  • @Wodsobe
    @Wodsobe 4 роки тому +7

    Before the adjusting to the environment part, I was wondering why my dude was clipping through the obstacle. Then you covered that. It's very cool that it adjusts according to the ceiling height! Thanks!

    • @garbaj
      @garbaj  4 роки тому +4

      Thanks, I'm glad you found it helpful

    • @frankoesavage8314
      @frankoesavage8314 4 роки тому

      that was intense, i thought for sure id catapult somewhere

  • @AleksandarPopovic
    @AleksandarPopovic 4 роки тому +4

    Keep going man, good work, good tutorail, and good luck for your project!!!

  • @ZZKJ396
    @ZZKJ396 4 роки тому +5

    Bippity, bappity, bop... done! Nice!

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

    I would add if "Input.is_action_pressed("crouch") or is_bonked" to replace "if Input.is_action_pressed("crouch")", so if you are stuck in a place like in csgo, when going to mid window from ct spawn, there is that little entrance where 4:25 is applying. The player will still be slowed down when crouching, not like before when you let go of ctrl you can run as a croucing player :)

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

      Thank you for this comment
      THe way you do it changed so now its - if Input.is_action_pressed("crouch") or head_bonked:

  • @pascalcasier959
    @pascalcasier959 4 роки тому

    excellent job, thank you again

  • @gorudonu
    @gorudonu 4 роки тому +9

    Nice tutorial! It could be cool if you download some character from Maximo and set all animations and model with your code

    • @garbaj
      @garbaj  4 роки тому +2

      That’s actually a good idea, I’ll put it on the list

  • @lethn2929
    @lethn2929 3 роки тому +7

    I know this is a fairly old video now but I thought I'd post this up in case people were having the same problems as me, two things I would warn about this player controller but they're fairly minor annoyances that you need to work through. If people are having issues with crouch 'doing nothing' double check the height your player is set at and increase it if the height is lower than the height of the player capsule there will be only a small movement and the camera and capsule won't shrink correctly. I also noticed a bug with this controller where if you try to make a vent to jump through like in the old Half Life games and crouch into it when you release the crouch button inside the vent the player and I think it's because the controller still thinks somehow it's in midair so it defaults to player 'falling' and using gravity so it gets stuck in the floor because it seems to unshrink itself.
    Anyone got any ideas? I might suddenly fix this problem but we'll see, will post an update if I do.
    Edit: Okay I just figured it out and the problems are to do with the height of the obstacle you're ducking under when you release the crouch action if you decrease the height of the obstacle above you then the player sinks into the ground so you need to experiment and match the height difference with whatever settings you've chosen. When placing the obstacle matching the height difference to the size of the capsule seems to fix it, after that you've just got to scale everything to make it all look right like if you were doing what I wanted to do and make a vent to crawl through for example.

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

    ok, so im slowly learning gdscript and i have started changing your code while watching tutorials for my ease. lets see how this works haha

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

    4:05 im using the improved tutorial which uses gravity_vec
    is there like any other way to replace fall.y

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

    I did this in a more convoluted way, but I gotta say it works like a charm.
    - I used two collision shapes, one high and one short, and I alternate between both when I crouch/uncrouch.
    - I have an AnimationPlayer to move the camera, both for crouching and for peeking around corners. This lets me control the movement curve, to do some easing while still keeping the movement quick and snappy.
    - I also use 5 head bonker rays, one in the center and one in each corner (very slightly offset inwards), but only for preventing uncrouching when crouching under low ceilings (I never had the problem of getting stuck on them). So you can let go of the crouch key when you go into a small tunnel, and then it will uncrouch automatically when you get out of the tunnel (my *stand_up()* function checks the rays for collisions).

    • @garbaj
      @garbaj  4 роки тому

      That's a pretty clever solution! There's always more than one way to do anything in programming

    • @skaruts
      @skaruts 4 роки тому +2

      @@garbaj Indeed. My initial thoughts were to do it kinda like you did it, but I had some trouble with it, and also I didn't quite know how to move the camera gradually over time back then... So I had to come up with something else.
      Now I only have to figure out how to also add a view bobbing animation, as well as how to fix the peeking ones, because they don't seem to all play along nicely. I suspect I may have to either implement some sort of state machine, or use the AnimationTreePlayer (or whatever its called), or use a second animation player, which also should work.

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

      @@skaruts teach me how to do your crouch system, pls

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

    Yep, I think garbaj just made an inconsistent video, in this tutorial he references the 'CollisionShape' which used to be a node called body and the collision shape you're change the height of is 1.5 whereas the body in the previous video has a height of 3. Just something to watch out for, wonder if he edited the video awkwardly and didn't double check things because all of a sudden when I change my settings to match what he's done in this video it works better.

  • @8epic819
    @8epic819 4 роки тому +1

    I have an error,"Attempt to call function 'is_colliding' in base 'null instance' on a null instance" when i try to get the raycasting node

  • @thealfax9992
    @thealfax9992 4 роки тому

    Y like your videos bro I think they re really helpful fr the community, you should do how to put a caracter and a weapone for the next one

    • @garbaj
      @garbaj  4 роки тому

      Coming soon ;)

  • @chef2654
    @chef2654 4 роки тому +2

    I'd love a tutorial on a dynamic 3rd person camera. An over-the-shoulder view, You know, that zooms in when you walk, and out when you run / when enemies are nearby

    • @garbaj
      @garbaj  4 роки тому +2

      I was thinking about making a video on this, but I’ll probably have to do a lot of research. Thanks for the idea :)

    • @chef2654
      @chef2654 4 роки тому +1

      @@garbaj Thanks for your awesome videos :)

    • @fragarena9910
      @fragarena9910 4 роки тому

      @@garbaj idk if godot has a 'springarm'(this is what unreal uses. we may have to make a makeshift one using raycasts

  • @leo28804
    @leo28804 4 роки тому +2

    if you are using a "feet" collision on your controller and use this, my character flies up, so I found that you can just use the crouch height for crouching down and default height for up and it fixes this issue
    NB= do not add plus or minus to the equals and only multiple crouch height by delta if not you wont move at all
    ...could be just me

  • @BrunoSilva-rr6cb
    @BrunoSilva-rr6cb 4 роки тому

    Great video!

  • @brownish-fox3194
    @brownish-fox3194 Рік тому +1

    what if I want the mesh instance? I tried to do with it but the game became very laggy.

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

    Hey how could i do sliding like that i keep momentum, and when sliding down slopes i keep getting more speed?

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

    Problem: When you walk from flat ground onto an inclined ramp while crouching, it works fine, but when you go down the other way back onto flat ground, the player can't pass the line where the two meet. Anyone know a fix for this? Is it just me? EDIT: Seems to be only ramps maybe 45 degrees or greater.

  • @moonthurst
    @moonthurst 4 роки тому

    Very nice series. Thank you.
    I know there is a project out there for Godot multiplayer fonction.
    So I was wondering if you ´ll show us how to make our enemy see us. (Proxy character .? ) ??
    Also maybe in a future video, how our player can run on walls

    • @garbaj
      @garbaj  4 роки тому +1

      I hope to make videos on those subjects in the future, I just need to learn how to do it

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

    For some reason, when multiplying by delta, even without the clamp line written, the player just crouches a little, which is a little odd. For now, I'll just do it without multiplying by delta, but, does anyone know why this happens? My game is capped at 60 fps, but still, I would want the crouch speed to be the same for everyone. I increased the crouch speed, but the only thing that does is changing how much you crouch.

  • @Mriganka2S
    @Mriganka2S 4 роки тому +4

    For the crouch thingy, I have an advice. Instead of changing the collision shape via code, change it via the animation player, that way you can crouch (play) and (un)crouch (play_backwards) quite seamlessly since they will be using the same animation track. PS - do not change the "scale" of the collision shape, it doesn't work, you have to change it's "shape".

    • @garbaj
      @garbaj  4 роки тому +2

      I agree, in this tutorial I change the shape of the collider rather than adjust it's scale, and the result is very smooth. Thanks for the tip!

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

      I tried this method but the animation keeps looping.

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

      @@aryabratsahoo7474 You may have set your animation to be loopable. Check your animation track to see whether the animation is loopable.

    • @aryabratsahoo7474
      @aryabratsahoo7474 Рік тому +1

      @@Mriganka2S It's not looping in the animation player. The problem was that it was constantly being updated in the code every frame, so I fixed it by implementing various boolean checks to have it run once.

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

      @@aryabratsahoo7474 Nice man. I would recommend you set up a nice state machine to go with the animations. They make live way easier.

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

    I'm having a problem. I'm trying to figure what to use in place of fall.y since the controller I use is made following your improved FPS controller tutorial. I though I could use gravity_vec, but that just caused an error in my script saying "Invalid get index 'z' (on base: 'int')." Am I missing something?

  • @glennglog22
    @glennglog22 Місяць тому

    When attempting to implement the headbonking to another FPS controller, it seems that when the head is bonked, my character is permanently stuck crouching. It could likely be because the way the code works is different now due to me using Godot 4.1.1 in my project vs whatever version is in this video. Has anyone else run into this, and if so, have any advice on how to fix this?

  • @chelovek-jpeg
    @chelovek-jpeg 3 роки тому

    great! thanks :)

  • @Polezno_znatb
    @Polezno_znatb 4 роки тому

    Please help me I did everything as in the video but my character does not squat

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

    pcap.shape.height does not work in Godot 4. Do you know what is the alternative?

  • @fallout4enjoyer
    @fallout4enjoyer 4 роки тому

    Best UA-camr!! Please make a tut to teleport from a translation to translation in 3D please

    • @garbaj
      @garbaj  4 роки тому +1

      This one is pretty simple. Let's say you have a script on the object you want to teleport and the location you want to teleport to is Vector3(12, -32, 0). All you need to write is:
      transform.origin = Vector3(12, -32, 0)

  • @ULTRABEAN-zh5wz
    @ULTRABEAN-zh5wz 4 роки тому +3

    When I tried to run the program there was an error that said The function ‘move_and_slide()’ returns a value, but this value is never used

    • @caffeinatedPopcorn
      @caffeinatedPopcorn 4 роки тому

      It's not an error, just a warning. You can safely ignore it

    • @ash.n51
      @ash.n51 3 роки тому +2

      Wow that came out of nowhere

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

    Hello, how to make power slide on fps controller?

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

    Whenever I press the control key it doesn't work, I dunno why😐

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

    for anyone working in third person games.... just add two collision shapes one for the legs and one for the torso, it won't influence how damage works so don't worry and then disable the torso collision shape when crouching :
    if Input.is_action_pressed("crouch"):
    collisionTorso.set_disabled(true)
    else:
    collisionTorso.set_disabled(false)

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

      this way you can avoid a bunch of problems with clipping through terrain or if you are using free movement without fps straving the method in the video just wont work.

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

    is there a way to do this in the improved fps code?

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

    Hey Garbaj, I have followed this tutorial to the letter a few times over, and my character still won't crouch. The movement speed corresponds to the crouch movement speed, so it is not an input issue, and the collision box size changes also, but the axis on which it's centered stays the same, so the capsule just gets smaller on both the top and bottom edges. FYI I am using the advanced FPS controller model.

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

      I bet it's because the advanced fps controller uses 2 collision shapes instead of one. If you want, you can get rid of the foot collision shape entirely or change the whole thing into a single cylinder shape which I believe should fix the problem, or you can code the capsule to move down when crouching if you want to stick with the 2 collision shape version

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

      @@garbaj ah thank you!!! I ended up deleting the capsule.

  • @jamesxxxyz8775
    @jamesxxxyz8775 4 роки тому

    Sprint with endurance/cooldown. cooldown when player walk, faster while standing, with crouch and sneak too?

    • @garbaj
      @garbaj  4 роки тому

      I'll be covering most of this in the next advanced fps movement video

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

    cant you just hide the mesh instance node instead of deleting it?

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

    maybe do tutorial on vaulting?

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

    and uh i cant crouch even with the identical code
    im using your advanced controller and it worked fine with wallrunning so why doesnt this work?
    if Input.is_action_pressed("crouch"):
    pcap.shape.height -= crouch_speed * delta
    speed = crouch_movespeed
    else:
    pcap.shape.height += crouch_speed * delta
    pcap.shape.height = clamp(pcap.shape.height, crouch_height, default_height)

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

      did you happen to solve that problem? 'Cause I'm having the same issue

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

    nice

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

    okay so i have an issue with the head bonker bit,
    I am using:
    if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()):
    gravity_vec = Vector3.UP * jump
    however if i add:
    if head_bonked:
    fall.y = -2
    it doesn't work as fall.y isn't part of the script (I am using the improved fps code).
    I'm relatively new to Godot and sucky when it comes to coding, if someone could provide a solution please tell me this is doing my head in.

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

      Its likely you already found this considering I took it from an earlier comment, but adding this instead of the head bonker code should work:
      if is_on_ceiling():
      >gravity_vec.y = 0

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

      @@abstractlime101 thank you i am quite new. I added that bit of code underneath the jump code but it still hasn't worked.
      Did i miss something/put it in the wrong place?

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

      @@crowman9096 I put it above the jumping code.
      It might also be if you actually put a ">", that is meant to represent an indent.

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

      @@abstractlime101 dude thank you so damn much! What would I do without people like you
      I put it above the jumping code and it works perfectly!

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

      @@abstractlime101 one issue however haha. The last problem with the character collision clipping into the objects, causing jerky movement. I did this:
      elif not is_on_ceiling():
      pcap.shape.height += crouch_speed * delta
      but I still face the issue. Any ideas?

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

    There seems to be a limit on how far down the cam will go

  • @vinnieyang5422
    @vinnieyang5422 4 роки тому

    I have an issue where the player gets stuck while moving underneath a large platform in a state between standing and crouching

    • @garbaj
      @garbaj  4 роки тому

      I cover how to avoid this near the end of the video. Did you make sure to implement the headbonker raycast that I talked about?

    • @vinnieyang5422
      @vinnieyang5422 4 роки тому

      @@garbaj I did. here's what I have for the code if you don't mind looking: pastebin.com/v53YZKru

  • @Yoni123
    @Yoni123 5 місяців тому

    Works with godot 4?

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

    I think many dont understand how EASY it is to do somewhat complicated issues. Nice 👍

  • @d-man4485
    @d-man4485 4 роки тому

    How did you make a 3D environment (like the one you made. sorry, I'm new to godot)

    • @garbaj
      @garbaj  4 роки тому

      I suggest starting with a beginner's tutorial like this one: ua-cam.com/video/-D-IcbsdT04/v-deo.html

    • @d-man4485
      @d-man4485 4 роки тому

      Garbaj Thanks!

  • @marcojakobgorospe7447
    @marcojakobgorospe7447 4 роки тому +6

    whenever I crouch, my character falls through the ground

    • @frankoesavage8314
      @frankoesavage8314 4 роки тому +1

      lol, yo thats sick, can i have those codes?

    • @frankoesavage8314
      @frankoesavage8314 4 роки тому +1

      Shit Bro, Becareful what you wish for. I am redoing the tutorial for cleaner coding. And i ran into this exact problem bro. wtf, Were u trying to level everything out perfect as well?

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

      I know this is an old comment but just in case, the player will go through the ground if the obstacle you're crouching under isn't high enough, make adjustments according to your height settings.

  • @frankoesavage8314
    @frankoesavage8314 4 роки тому +1

    ah man, i really messed up. My guy is sprinting!....I gotta re do this or keep it as sprint feature

    • @frankoesavage8314
      @frankoesavage8314 4 роки тому

      i had a - instead of a + enabled crouch, im guessing my default speed is to high making it go quicker.

    • @garbaj
      @garbaj  4 роки тому

      The joys of programming

    • @frankoesavage8314
      @frankoesavage8314 4 роки тому

      @@garbaj yeah its all good now, im moving on to the clipping part with raycast. Hoping by the end of the week I have a working fps controller merged with my next weeks lessons.

  • @hshsjsjsj506
    @hshsjsjsj506 4 роки тому

    we need cross hair tut haha

  • @jamesxxxyz8775
    @jamesxxxyz8775 4 роки тому

    You don't need to write subtitles, because UA-cam can generate it, maybe you should write it as info at the start. Only when you write code you should write this in bigger subtitles.

    • @garbaj
      @garbaj  4 роки тому +1

      Interesting, do you find the subtitles distracting? I've been doing the subtitles myself since the autosubtitles aren't always accurate, but it's definitely a lot of work

    • @jamesxxxyz8775
      @jamesxxxyz8775 4 роки тому

      @@garbaj I think it is unnecessary and a question of time. You don't need to subtitles, but it is better when you write gdscripts in the description, or better you use GitHub like Gdquest. You can upload files there too.

    • @garbaj
      @garbaj  4 роки тому +1

      Thanks for the feedback

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

      @Garbaj UA-cam's subtitle generation sucks when you are not speaking flawless English or when you use technical terms that aren't frequent in the dataset they use to train the neural net, I would caution against relying on youtube's machine learning translation.

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

    i dont duck, i go slower though but my camera doesnt move down

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

      Hey this is happening to me too, did you find a solution/fix?

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

      @@comfyzenny no sorry

  • @angie064
    @angie064 9 місяців тому

    Does this still work on godot 4.1 ?

    • @ciaranhappyentriepaw
      @ciaranhappyentriepaw 4 місяці тому

      yes in principle, but his specific implementation will throw compiler errors. Ive been trying to adapt this to my modular controller and it mostly works. only problem is gravity isnt being applied correctly after the colliders been shrunk - i suspect thats more due to whatever ive done than what Garbaj did though.

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

    Nothing happens when I try to crouch:(

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

    everything was working fine and then after adding this my whole project is corrupted this is the second time

  • @purgegamesstudio4937
    @purgegamesstudio4937 4 роки тому

    who do you make a gun

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

    bonk

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

    I'm using this tutorial in Godot 4
    And I'm having trouble with the pcap.shape.height line, it keeps telling me, "Invaild get index "height" (on base: 'ConvexPolygonShape3D')
    Does anyone know a fix for this?

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

    if is_on_ceiling():
    > gravity_vec.y = 0

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

    im just getting errors when i play

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

      nvm i just forgot to write something in the code, nice tutorials btw