Juiced Up First Person Character Controller Tutorial - Godot 3D FPS

Поделиться
HTML-код
  • Опубликовано: 10 дек 2024

Комментарии • 839

  • @legiongames2400
    @legiongames2400  Год назад +208

    As badunius pointed out, a capsule shape is better for collision because it is a simpler shape. When you're creating a collision shape make sure to use that. This has been updated on github. Also make sure to turn on collisions for any CSG boxes you add or you will fall through the floor.

    • @tftc97
      @tftc97 Год назад +3

      where do i do that????????????????????????????
      edit: nvm

    • @kinggreen9073
      @kinggreen9073 Год назад

      I said the same thing bro@@tftc97

    • @Kirico_gd
      @Kirico_gd Год назад +1

      hey do you still reply under older videos, if yes do you know why my camera moves on both x and y axis when i load the game

    • @sourlesscream1272
      @sourlesscream1272 Год назад +1

      @@Kirico_gd Head pivot is for horizontal rotation and Camera is for vertical
      the camera portion of the script should look like this
      head.rotate_y(-event.relative.x * SENSITIVITY)
      camera.rotate_x(-event.relative.y * SENSITIVITY)
      camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-45), deg_to_rad(45))

    • @dynstinn
      @dynstinn Год назад +1

      can you add crouching please, i need this character controller for a horror game im making, i REALLY need crouching

  • @pixels_per_minute
    @pixels_per_minute 8 месяцев назад +79

    One of the best First Person tutorials I've ever found for Godot.
    A LOT of other videos seem to throw out the sample code for far more complex code that just dose the same basic stuff in a different way. I like how you just build off it instead, and provided us with a simple, yet highly configurable base.
    I also learned a few tricks I can apply in my 2.5D character controller since it also uses the same sample code.
    From here, I'll be looking to add in a raycast system in order to see what the player is looking at and maybe a menu system, which I now know how to do thanks to people like you!

    • @legiongames2400
      @legiongames2400  8 месяцев назад +4

      Thank you friend! :) I'm really glad I get to help out

  • @yusarimahubara
    @yusarimahubara Год назад +49

    The best simple head bob I could found in the internet, the other ones are overcomplicated and they didn't seem so nice, great job!

    • @legiongames2400
      @legiongames2400  Год назад +4

      Thank you! :)

    • @DePistolero
      @DePistolero 10 месяцев назад +2

      YES, elegant, simple, tweakable, straightforward and bulletproof... Just starting godot( turnover from Unity ) more than 7 yrs of xp...

    • @Papajoofable
      @Papajoofable 6 месяцев назад

      ​@@legiongames2400Hey man! Cool vid, i really like that headbob. But, how can i make footsteps sounds with it? (I hate animation player and blend tree headbobbing)

    • @menacingskull740
      @menacingskull740 5 месяцев назад +2

      THE POWER OF ACTUALLY USING MATH AND ACTUAL FUNCTIONS IN GODOT

    • @ScratchyBlade7634
      @ScratchyBlade7634 5 месяцев назад

      i cant get it working and my camera is jsut stuck halfway in the floor for some reason

  • @badunius_code
    @badunius_code Год назад +177

    0:45 technically capsule collision shape gotta be better for perfomance, because you have to solve just one primitive collision, whereas a convex hull is solved on per face basis.

    • @legiongames2400
      @legiongames2400  Год назад +25

      Oh yeah that actually makes sense.

    • @deadturret4049
      @deadturret4049 Год назад +6

      way better for performance. You could argue that the capsule is calculating 3 shapes, (2 spheres, 1 cylinder), but the calculations to do those is ludicrously simple and fast. Switching to face collisions is not great.

    • @Spuds1411
      @Spuds1411 9 месяцев назад +3

      I've always just used a cylinder for character collisions! I've found its the simplest possible shape which also gives the best results for collisions!

    • @souvikdatta97
      @souvikdatta97 3 месяца назад

      ​@@Spuds1411when it comes to slopes though I think it is better to use capsule

  • @BurritoByte
    @BurritoByte Год назад +21

    Hello LegionGames!
    I wanted to thank you for creating this video. I recently wrapped up my Godot 4 FPS prototype and this video played a monumental role in getting the initial player controller implemented and working for my project. I just published my video of it on my page and have added you in the game's credits as a thank you for this tutorial video.
    Thanks so much again and looking forward to future uploads!

    • @legiongames2400
      @legiongames2400  Год назад

      Thank you friend! :) I'm really glad it helped you out!

    • @WeirdBrainGoo
      @WeirdBrainGoo 2 месяца назад +2

      A 4 FPS game sounds pretty slow, I hope you can bump it up to 5 in the future. 🤞

  • @jasonleeroberts
    @jasonleeroberts 7 месяцев назад +37

    this was amazing. incredibly fast, and concise. thank you! for any new game devs like me who couldn't figure out the collision at the beginning of the video: Just click CSGBox3D, and in the CSGShape3D menu on the right, click the checkbox next to "Use Collision". Make sure to do this for the other boxes you make for the level too. You can CTRL+click all the boxes you want to add collision to and add it to all of them at once.

    • @jaythewolf7216
      @jaythewolf7216 4 месяца назад +3

      big help thank you. i was going through and adding a collision node to everything lol

    • @AdrianLong-yx6zh
      @AdrianLong-yx6zh 4 месяца назад

      Thank you so much.

    • @MichToffen
      @MichToffen Месяц назад

      Life saver

    • @humanrich
      @humanrich 18 дней назад

      Upvotes for you!!

    • @sarov5353
      @sarov5353 День назад

      Thx

  • @Dawid30303
    @Dawid30303 Год назад +22

    great tutorial, thanks a lot. To anyone new to godot, if you are confused about what a function is doing, then i recommend printing out the variable the function is modifying. This helped me understand a few things a bit better

    • @legiongames2400
      @legiongames2400  Год назад +12

      That's a great idea even if you're not new to godot haha, thank you for watching!

  • @wolcamophone4783
    @wolcamophone4783 Год назад +106

    I find it easier to pull better snippets of code and explanations from random tutorial vids than to watch tutorials on specific subjects as some tutorials will mislead you from what you want to actually accomplish in your code.

  • @wilmernyman
    @wilmernyman Месяц назад +3

    Great tutorial!
    You went a little bit fast at times, but manageable with some rewinding. You explained everything done, which is a huge help with being able to manipulate the code without much prior coding experience. Keep up the good work!

  • @badunius_code
    @badunius_code Год назад +69

    5:15 or even better, you can rotate your entire body along the Y axis and not just your head. Shadows will give you away if you'll switch to a non symmetrical body.

    • @legiongames2400
      @legiongames2400  Год назад +8

      Very good point.

    • @Jacklo-the-catsect
      @Jacklo-the-catsect Год назад +5

      thank you for this, until I rotated the head, the body didn't rotate, and so I looked backwards then walked forwards, I'd be going backwards, but rotating the body fixed that.

    • @itsaducklin
      @itsaducklin Год назад +3

      ​@@Jacklo-the-catsect well thats cause you multiplied the direction by the forward vector of your actual player, not your head
      (not trying to justify using the head, just sayin)

    • @cassis2325
      @cassis2325 Год назад +1

      This fix is also better in the way that now your starting rotation of the body doesn't have to be zero in the engine. Now you can rotate the entire body to your hearts content in the engine without it messing up local an worldposition's whilst walking

    • @mattg6550
      @mattg6550 Год назад +25

      Just for anyone running into trouble here, you will be replacing head.rotate_y(-event.relative.x * SENSITIVITY) with rotate_y(-event.relative.x * SENSITIVITY) to accomplish this, since if we rotate_y (or do any translations or rotations without specifying what we are translating or rotating) we will enact this on the 'scene' that the script is attached to, in this case the root "Player"

  • @Flexyhandz
    @Flexyhandz 2 месяца назад +4

    Sifted through like five other camera videos and this is the one that solved my problems.

  • @jorge2555
    @jorge2555 4 месяца назад +5

    I won"t lie I had trouble keeping up but this tutorial helped me figure out how to apply inertia easier so thank you for that hopefully ill be able to comprehend the rest as i continue messing with Godot. Wish me luck!

  • @t3st3d
    @t3st3d Год назад +8

    thanks! i just switched from unity to godot and this is the most helpfull tutorial i have found so far

    • @legiongames2400
      @legiongames2400  Год назад +5

      Hey welcome to the engine haha, I'm glad you're enjoying my videos

  • @DanTheman-z4w
    @DanTheman-z4w 3 дня назад

    idk if you see this but thank you! I get really discouraged when I look at godot tutorials and they are like 1-10 hours long, a series with 10-20 minute videos is perfect for me! Happy holidays! (if you celebrate any)

  • @MerrStudio
    @MerrStudio 10 месяцев назад +6

    One thing that's easy to miss cause the effect is subtle but if you have no velocity you don't reset t_bob value so your camera could be shifted ever so slightly from the bob when not moving anymore.

  • @indieology7336
    @indieology7336 Год назад +13

    This is awesome! Thank you for your great work!

  • @stevedowning3892
    @stevedowning3892 Год назад +2

    Absolutely wonderful tutorial, thanks so much. I am a rank n00b to game dev in general, having downloaded Godot last week. I found it super instructive to type the script along with the video, but to use the Git download to help with fault-finding, when I inevitably made mistakes.

  • @MizziePeasy
    @MizziePeasy 6 месяцев назад +1

    I am starting now on the game dev world and this was the first video I found that didn't bore me to death! Straight to the point and great humour! I was planning on doing a single player arena shooter and you have the perfect video.
    Thank you so so much, I really hope you have lot of success in your life ☺

  • @MichaelFoxtrot
    @MichaelFoxtrot Год назад +7

    I have never had to pause a video so many times lol
    10/10 would recommend

  • @captainnelson9833
    @captainnelson9833 Год назад +2

    This is the best tutorial for a FPS character controller. Your code is just too clean for human eyes.

  • @thricemindblown7883
    @thricemindblown7883 Год назад +3

    My favourite was the headbob function. That "->" should come in handy.

  • @homborgor
    @homborgor 2 месяца назад +14

    Tip for people:
    When you set up the sprint mechanic, we start it with "if Input.is_action_pressed("Sprint"):"
    before starting the next line, add "and is_on_floor()" to make sure that the player cant "sprint" in the air, this also stops the player from being able to shoot forward in the air after standing still. So overall, you code should look like:
    if Input.is_action_pressed("Sprint") and is_on_floor():
    speed = SPRINT_SPEED
    else:
    speed = WALK_SPEED
    Just swap it out if you want ✌✌

  • @Marcusvlogs
    @Marcusvlogs 6 месяцев назад

    Really good tutorial. I like that it was fast and informative but didnt get bogged down into every little gritty detail

  • @ivan-_-8577
    @ivan-_-8577 5 месяцев назад +1

    Thank you. A very nice controller and lots of clear and useful code examples!

  • @FinleyRounds-d6c
    @FinleyRounds-d6c 26 дней назад

    Thank you so much! This tutorial was very helpful, and I was so lucky to find your channel!

  • @DarkestMirrored
    @DarkestMirrored 9 месяцев назад

    this seems very useful! the one thing i'd REALLY like to see would be stair handling? none of the player controller tutorials seem to care about being able to use stairs.

    • @legiongames2400
      @legiongames2400  9 месяцев назад +1

      Yeah stairs are a little more difficult tbh, I would love to make a more complete controller one day, but there's a really well-made video that describes the concept in general concepts: ruclips.net/video/ILVUc_yV24g/видео.htmlsi=rZX2XExOCMyssIs3

  • @LaurenNapier-uk4yk
    @LaurenNapier-uk4yk 9 месяцев назад +1

    This was exactly what I needed while I'm learning, thank you! Now for that extra juice I gotta find some way to add a little acceleration and hopefully a faster initial jump speed like source games...

  • @Combinehuntsmanunit
    @Combinehuntsmanunit 3 дня назад

    I know a lot of people dislike the speed you have but for someone who is already somewhat familiar with programming it makes it easier to work. Also I like not having every detail of programming retaught to me like I know nothing lol

  • @victorguisf
    @victorguisf 2 месяца назад

    This was amazing and so straight forward! Thank you for sharing this!!

  • @okayoni6342
    @okayoni6342 3 месяца назад

    Holy cow this one is a ton better than the other 40 minute tutorial I saw.

  • @m0nste_
    @m0nste_ 9 месяцев назад

    Thank you so much for this tutorial. I've never really gotten into coding before, so I'm attempting to learn Godot to get into the swing of things. I would love to see another video perhaps diving into crouching implementation as well as crouch sliding! :)

  • @mhp9868
    @mhp9868 3 месяца назад

    I'm not into making games but it was really fun to play around in Godot. Looking forward to add guns and zombies. Thanks for the tutorial!

  • @Godot-Bro
    @Godot-Bro 3 месяца назад

    Thanks for this! I'm pretty new to Godot and only just now touching 3D. Very helpful resource.

  • @_phloggy_
    @_phloggy_ Год назад +2

    amazing vid, i've understood pretty much everything you've taught me, thank you!

  • @murrrr8288
    @murrrr8288 2 месяца назад

    Great video! Exactly what I was looking for :)

  • @WeirdWimp
    @WeirdWimp 7 дней назад +1

    5:11 it says Line 32:Cannot infer the type of "direction" variable because the value doesn't have a set type

  • @Paulik76910
    @Paulik76910 Год назад +2

    Thanks for such a detailed tutorial.

  • @InHUM44n
    @InHUM44n Год назад +14

    For anyone wanting to untie player movement from physics tickrate: For me moving move_and_slide() to _process(delta) instead of _physics_process(delta) fixed the "laggy" 60fps camera translation movement. Now my physics framerate is 30 to save performance on the CPU and it still feels good :)

    • @kabebu_
      @kabebu_ Год назад

      I've been searching for the cause of those "lag spikes" for 2 days... Thank you :')

    • @annoyingkittycat6449
      @annoyingkittycat6449 11 месяцев назад

      I've heard if a big lag spike hits it can completely mess up your physics engine if you do this from another youtuber, but I'm not sure if its true

  • @tje.o.a5477
    @tje.o.a5477 8 месяцев назад

    Thank you my dude, this has helped me remake my character controller after I switched to fps!

  • @GamerPieOfficial
    @GamerPieOfficial Месяц назад

    This helped out so much, Game development career here i come!

  • @ck88777
    @ck88777 5 месяцев назад

    great tutorial btw, good pace and straight to the point, just the way a tutorial should be

  • @TheMisterNebo
    @TheMisterNebo Год назад +7

    Your content is great, you have a good pace (I like the 'faster' pace that you use), and Godot will be all the hype soon enough thanks to Unity's foolery. I subscribed, thank you so much for taking your valuable time to make this content for us. You make learning Godot fun!

  • @ProbablyM_S
    @ProbablyM_S Год назад +6

    you can include camera tilt when moving in a direction it looks really cool in part 2 ,can add sound effects for jumping,landing, running, add particles and crouch/sliding hehe ik its too much but would love to see that

    • @legiongames2400
      @legiongames2400  Год назад

      Yeah all of these would be really important for most games!

    • @ProbablyM_S
      @ProbablyM_S Год назад +1

      @@legiongames2400 is this a taunt or you are serious? 😂

    • @legiongames2400
      @legiongames2400  Год назад +1

      @@ProbablyM_S LMAO my bad if that sounded sarcastic. No, I'm serious, sound effects are a little tricky here so would be cool to do a vid on that. Plus extra camera movement like a little drop when you land, tilt on strafe, etc would make it even more juicy.

    • @ProbablyM_S
      @ProbablyM_S Год назад

      @@legiongames2400 haha its fine

    • @px8
      @px8 Год назад

      @@legiongames2400 you should do this!! pleaase!

  • @RandomGuyyy
    @RandomGuyyy Год назад +1

    This video and the following in this zombie fps series are a good introduction to 3D in Godot 4.

    • @legiongames2400
      @legiongames2400  Год назад

      Haha thank you! :)

    • @RandomGuyyy
      @RandomGuyyy Год назад

      @@legiongames2400 proper shooter tutorials with actual animated characters are thin on the ground for Godot so I hope the.algorithm catches wind of it.

  • @iwolfman37
    @iwolfman37 Месяц назад +2

    Tried following the tutorial but my player keeps falling through the CSGBox whenever I run the game. So I'm stuck at about the @1:30 minute mark. Also pls say in the future how you do simple things like resize the mesh

    • @ICantCodeHELPME
      @ICantCodeHELPME Месяц назад +3

      here is how to fix it so first you click the box and go into the panel on the right it says use collision, check that and it should work i had the same issue

  • @LexGear
    @LexGear 11 месяцев назад +3

    One thing I noticed is that there was a blurr on the edges of ojects when rotating the camera, this is because the rotation is calculated on the physics layer intbeween frames when it should be calculated on the frame layer _process().

  • @sonicfan826
    @sonicfan826 Год назад

    This really helped me out, thank you for the tutorial and have a nice day

  • @bloxtrider
    @bloxtrider 7 месяцев назад +2

    is it just me or all the godot tutorials way better and easier to understand than the unity ones...

    • @legiongames2400
      @legiongames2400  7 месяцев назад +1

      Godot is easier to understand than unity :D That's why I use it

    • @calumwoodward9489
      @calumwoodward9489 7 месяцев назад

      @@legiongames2400 please help im stuck in the ground even when i use your code from git

  • @THEBESTDEV-w2x
    @THEBESTDEV-w2x 2 месяца назад +3

    Cannot infer the type of "direction" variable because the value doesn't have a set type. at 5:15

    • @humanrich
      @humanrich 18 дней назад

      Remove the semi-colon before "= (head.transform....."
      That's the fix I found online. Not sure if he does it earlier in the video without showing or if the newer version of Godot puts it in.

  • @blue123-m7h
    @blue123-m7h 2 месяца назад +1

    Thanks for Tutorial LegionGames🤩😍🥰

  • @BlueCodingStudio
    @BlueCodingStudio Год назад +1

    Very useful, I am too lazy to write my own code, so hippity hoppity your code is now my property.

    • @legiongames2400
      @legiongames2400  Год назад

      Wouldn't want it any other way, hope you're enjoying Godot haha

  • @cyclonebee2205
    @cyclonebee2205 Год назад +1

    Amazing tutorial! Learned a lot about gd script from this.

  • @jac0b_
    @jac0b_ 2 месяца назад

    super super awesome tutorial, thanks for your help and explanations

  • @OmniWareTeam
    @OmniWareTeam 6 месяцев назад +5

    If anyone is having issues with a certain error found in the console about _headbob. (This error: Standalone lambdas cannot be accessed. Consider assigning it to a variable.) The error you're encountering is due to the indentation of the _headbob function. In Godot, all functions need to be properly indented at the class level. Here is the corrected script:
    extends CharacterBody3D
    const SPEED = 6.5
    const JUMP_VELOCITY = 6
    const SENSITIVITY = 0.005
    const BOB_FREQ = 2.0
    const BOB_AMP = 0.08
    var t_bob = 0.0
    # Get the gravity from the project settings to be synced with RigidBody nodes.
    var gravity = 9.8
    @onready var head = $Head
    @onready var camera = $Head/Camera3D
    func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    func _unhandled_input(event):
    if event is InputEventMouseMotion:
    head.rotate_y(-event.relative.x * SENSITIVITY)
    camera.rotate_x(-event.relative.y * SENSITIVITY)
    camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-40), deg_to_rad(60))
    func _physics_process(delta):
    # Add the gravity.
    if not is_on_floor():
    velocity.y -= gravity * delta
    # Handle jump.
    if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = JUMP_VELOCITY
    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    var input_dir = Input.get_vector("left", "right", "up", "down")
    var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
    if direction:
    velocity.x = direction.x * SPEED
    velocity.z = direction.z * SPEED
    else:
    velocity.x = 0.0
    velocity.z = 0.0

    t_bob += delta * velocity.length() * float(is_on_floor())
    camera.transform.origin = _headbob(t_bob)
    move_and_slide()


    func _headbob(time) -> Vector3:
    var pos = Vector3.ZERO
    pos.y = sin(time * BOB_FREQ) * BOB_AMP
    return pos

    • @nickhurst7493
      @nickhurst7493 6 месяцев назад

      Thanks! This fixed my issue!

    • @wqiting_9545
      @wqiting_9545 3 месяца назад

      Hey thanks man! I just have a problem with the last part
      func _headbob(time) -> Vector3:
      The error is
      error at (52, 36): Expected intendet block after lambda declaration.
      Parser Error: Cannot use shorthand "get_node()" notation ("$") on a class that isnt a node.

    • @flyingchubandar8600
      @flyingchubandar8600 2 месяца назад +1

      Thanks !!

    • @nudgemepapi
      @nudgemepapi 2 месяца назад

      idk how this fixed my code but thank you

  • @thessonixx
    @thessonixx 2 месяца назад +3

    7:06 my camera going under my character

  • @AzizAllahverdiyev-h1q
    @AzizAllahverdiyev-h1q Месяц назад +5

    HEADBOB FIX:
    extends CharacterBody3D
    const SPEED = 5.0
    const JUMP_VELOCITY = 4.5
    const SENSITIVITY = 0.01
    const BOB_FREQ = 2.4
    const BOB_AMP = 0.08
    var t_bob = 0.0
    @onready var head = $Head
    @onready var camera = $Head/Camera3D
    var initial_camera_pos: Vector3
    func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    initial_camera_pos = camera.transform.origin
    func _unhandled_input(event):
    if event is InputEventMouseMotion:
    head.rotate_y(-event.relative.x * SENSITIVITY)
    camera.rotate_x(-event.relative.y * SENSITIVITY)
    camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-40), deg_to_rad(60))
    func _physics_process(delta: float) -> void:
    # Add the gravity.
    if not is_on_floor():
    velocity.y -= 9.8 * delta
    # Handle jump.
    if Input.is_action_just_pressed("ui_accept") and is_on_floor():
    velocity.y = JUMP_VELOCITY
    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    var input_dir := Input.get_vector("go_left", "go_right", "go_forward", "go_back")
    var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
    if direction:
    velocity.x = direction.x * SPEED
    velocity.z = direction.z * SPEED
    else:
    velocity.x = 0.0
    velocity.z = 0.0
    t_bob += delta * velocity.length() * float(is_on_floor())
    camera.transform.origin = _headbob(t_bob)
    move_and_slide()
    func _headbob(time: float) -> Vector3:
    var pos = initial_camera_pos
    pos.y += sin(time * BOB_FREQ) * BOB_AMP
    return pos

    • @LemurZZ
      @LemurZZ 29 дней назад

      Thank you bro, I've been looking for this error for 40 minutes...

    • @yungblurzz
      @yungblurzz 6 дней назад

      i-..... i love you

  • @Pixels_Universe
    @Pixels_Universe Месяц назад +1

    5:15 i cant do thing that you did its showing the error: "Cannot infer the type of "direction" variable because the value doesn't have a set type" please help.

    • @humanrich
      @humanrich 18 дней назад +1

      Remove the semi-colon before "= (head.transform....."
      That's the fix I found online. Not sure if he does it earlier in the video without showing or if the newer version of Godot puts it in.

  • @PastaMaster115
    @PastaMaster115 5 месяцев назад +3

    This is a suggestion for a good mouse handling format. That way you can capture and uncapture the mouse super easy and also the camera doesn't move when the mouse is visible.
    #Capture mouse handling
    if event is InputEventMouseButton:
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    elif event.is_action_pressed("ui_cancel"):
    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
    #Mouse movement
    if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
    head.rotate_y(-event.relative.x * SENSITIVITY)
    camera.rotate_x(-event.relative.y * SENSITIVITY)
    camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-40), deg_to_rad(60))

  • @StrawberryBongo
    @StrawberryBongo Год назад +1

    thanks so much bro this is such a huge help!

  • @TheValkire
    @TheValkire Год назад +2

    It would be amazing if you could do crouching and sliding based on current velocity (so you can slide down a slope).I've been trying to wrap my head around it for some days now without success... Great tutorial by the way!

  • @Drivinefire
    @Drivinefire 10 месяцев назад +2

    If you update camera bobbing inside the physics process won't the movement look jittery in higher refresh screens? I can't test it myself but maybe it would look smoother in the normal process.

  • @Hanham8turkey
    @Hanham8turkey 10 месяцев назад +4

    Every time I’d start up the game my “player” would fall through the floor.

    • @stupidsniper5216
      @stupidsniper5216 10 месяцев назад

      fax pls help

    • @finercandy45113
      @finercandy45113 10 месяцев назад +4

      enable collision on the csg box

    • @RayFwafwa
      @RayFwafwa 21 день назад

      @@finercandy45113 not all heroes wear capes

  • @davidmarinho2848
    @davidmarinho2848 Год назад

    Great tutorial!!! 👏👏

  • @patrick_30000
    @patrick_30000 День назад +1

    on 4.3 for the view bobbing for one of the last scripts func _headbob(time) -> vector3. It dosent work please help. It always says"Standlone lambdas cannot be accesed, please give it a variable"

  • @micahjorgenson8057
    @micahjorgenson8057 4 месяца назад +2

    For anyone who’s FOV was going way too high whenever they moved I found that changing the velocity_clamped variable at the very end of the line to SPRINT_SPEED * 1.3 instead of having it times 2 fixed the issue.

  • @laithalsaj5243
    @laithalsaj5243 Год назад +4

    Hey! I know this is a bit late for a 2 months old video but can you also show me how we can implement the crouch mechanic as well the slide? That would be very helpful from you, Great tutorial by the way!

    • @ince55ant
      @ince55ant Год назад +3

      for crouching, just scale down the collision on vertical axis and lower the camera position. also you should do a line trace when uncrouching to make sure your character has the space to stand up
      for sliding do the same stuff but also stop using the player input for movement/velocity but instead store the forward direction when the slide is first activated and use it for the movement, then decelerate to taste until equal to crouched walkspeed then start using normal crouching behaviour.
      also make a state machine for movement. i.e. make an enum for movement states like walking/crouched/sliding. then use a switch/match statement to set the velocity in the way each of those states requires

  • @abhatem
    @abhatem Год назад

    Great tutorial, thank you!

  • @joefigura6132
    @joefigura6132 Год назад

    Great video, succinct and helpful

  • @JosiahJuice
    @JosiahJuice 19 дней назад +2

    Funfact: If your player/character is falling through the floor, add a "StaticBody3D" child node to the floor!

    • @KrutoiPro2275
      @KrutoiPro2275 10 дней назад +1

      or just turn on the collision for the floor

    • @Leostruggler
      @Leostruggler 6 дней назад

      @@KrutoiPro2275 How to do that ?

    • @KrutoiPro2275
      @KrutoiPro2275 6 дней назад +1

      @@Leostruggler In the properties tab on the right side of the screen

    • @Leostruggler
      @Leostruggler 6 дней назад

      @@KrutoiPro2275 Found it just after making the comment lol! Thanks anyway!

    • @KrutoiPro2275
      @KrutoiPro2275 6 дней назад +1

      @@Leostruggler good luck with whatever youre working on!

  • @Harald723
    @Harald723 Год назад

    Great toutorial
    the code works perfectly and i can almost understand it!

    • @legiongames2400
      @legiongames2400  Год назад +1

      Thank you friend! Hopefully I can do better next time so you understand it all.

    • @Harald723
      @Harald723 Год назад

      @@legiongames2400 well im a beginner so I dont realy know how to code that much!

  • @thepowernerd0
    @thepowernerd0 Год назад +1

    Do NOT put a space in "Vector3" worst mistake of my life
    Very noob-friendly tutorial so far. This video is my first try at using Godot or any software. Gonna finish the sprint later today. Huge thanks!

  • @jordgoin
    @jordgoin Год назад +2

    Really cool stuff thanks. Out of curiosity how hard would it be to add something to handle stairs?

    • @legiongames2400
      @legiongames2400  Год назад +2

      Surprisingly complex topic tbh LOL Not too difficult but it is its own thing, check out this video ruclips.net/video/ILVUc_yV24g/видео.html

    • @JayTube7580
      @JayTube7580 Год назад +2

      I thought you just made an invisible ramp so they didn't get stuck on the stairs.

    • @Dailyfiver
      @Dailyfiver Месяц назад

      @@JayTube7580 Yeah id make an invisible ramp to act as the hitbox of the stairs. I agree with your logic haha.

  • @aisyahmichannel5833
    @aisyahmichannel5833 6 дней назад

    just like to ask but for some reason the "func _ready():Input.set_mouse_node(Input.MOUSE_MODE_CAPTURED)" part does not work on mine. it says "not found in gdscriptnativeclass" as the error

  • @6lua
    @6lua 8 месяцев назад

    Thank you so much! You helped me so much.
    Subscribed on you and liked the video.

    • @TupyBro
      @TupyBro 7 месяцев назад

      ооо, неожидал тебя тут увидеть, я делаю свою игру а тут ты в коментах

    • @6lua
      @6lua 7 месяцев назад

      @@TupyBro заебал

  • @monopoly2170
    @monopoly2170 Год назад

    Great job! I would recommend using similar lerp functions to add acceleration/deceleration

  • @homborgor
    @homborgor 2 месяца назад +1

    For people wondering if this is worth watching, I just paid for a Godot course and I'm referring to this because this is 110% better and is taught in half the time 💀

  • @greenspecgaming169
    @greenspecgaming169 6 месяцев назад +1

    Hey, if anyone is having issues with not being able to move, make sure 'move_and_slide()' is in 'func _physics_process(delta):'

  • @Jacklo-the-catsect
    @Jacklo-the-catsect Год назад +1

    this helped thank you, although I would suggest 0.007 as the sensitivity, as it's much slower, but still fast enough, it also doesn't make you feel like you're on a rollercoaster.

    • @legiongames2400
      @legiongames2400  Год назад +1

      Yeah people tell me my mouse sensitivity is too high all the time tbh. :D

    • @itsaducklin
      @itsaducklin Год назад

      i just multiplied it by the process delta time ._.

  • @user-un2vb8mr6e
    @user-un2vb8mr6e Год назад +4

    Great video, could you make a tutorial that implements head *sway* as well as head bob. Where the head kind of leans/ or rotates side to side when you move side to side similar to in games like Quake, Devil Daggers, Ultrakill, DUSK etc.

    • @legiongames2400
      @legiongames2400  Год назад +1

      That'd be a cool feature for a potential part two, thank you for the suggestion

    • @user-un2vb8mr6e
      @user-un2vb8mr6e Год назад

      @@legiongames2400 you're tutorials are really great for learning godot. Im currently halfway through the third video. You're second video really helped me understand how to use scenes to create prefabs. Although I've had to use shapes like cylinders, squares and circles as the collision shape for the static bodies because the convex shapes were really bad performance wise at least for me. Anyway keep up the great videos.

    • @cynkcaj
      @cynkcaj 7 месяцев назад +1

      on the off chance you still care about this, just throw "camera.rotation.z = lerp(camera.rotation.z, deg_to_rad(YOUR DESIRED DEGREES) * input_dir[0], delta * YOUR DESIRED RATE OF CHANGE)" in your physics_process

    • @user-un2vb8mr6e
      @user-un2vb8mr6e 7 месяцев назад

      @@cynkcaj thanks

  • @arrtemfly
    @arrtemfly Год назад

    oh this *was* very helpful and fun. thanks!

  • @Thph793
    @Thph793 6 месяцев назад +3

    I don't get it. I get like 1-2 fps but when I jump and during the jump/fall and while falling through the void i get perfect 60 fps even when moving the camera, what is this and how can I fix it? I know that my pc isn't that bad so I don't get why I only get good fps while jumping / falling. I already tried disabling the sun fro example but it didn't help 1 bit.

    • @WeirdBrainGoo
      @WeirdBrainGoo 2 месяца назад +1

      Did you double-check your code?
      FrostyyByte copy-pasted the whole code further below, so you can try copying it to make sure also.

  • @ryzenslt8943
    @ryzenslt8943 Год назад +1

    Omg thanks so musch all the tutorials Are so old and war

  • @johnc7389
    @johnc7389 Год назад

    Tremendously helpful.

  • @pixelpulsegamingXD
    @pixelpulsegamingXD 8 месяцев назад +2

    when i start the game, my camera falls to de ground and it like im an ant
    walking

    • @gemzi1426
      @gemzi1426 7 месяцев назад

      You had probably put the "camera3d" node in the top, you just need to put the "head" node instead, because it's the head node being at the position 0,0 that is actually making you have that problem (I hope you understand what I'm saying, I do not write that much at english, only my code is in english)

  • @FrostyyByte
    @FrostyyByte 6 месяцев назад +4

    if anyone is having errors blah blah:
    extends CharacterBody3D
    var speed
    const WALK_SPEED = 6.5
    const SPRINT_SPEED = 8.0
    const JUMP_VELOCITY = 6
    const SENSITIVITY = 0.005
    const BOB_FREQ = 2.0
    const BOB_AMP = 0.09
    var t_bob = 0.0
    # Get the gravity from the project settings to be synced with RigidBody nodes.
    var gravity = 9.8
    @onready var head = $Head
    @onready var camera = $Head/Camera3D
    func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    func _unhandled_input(event):
    if event is InputEventMouseMotion:
    head.rotate_y(-event.relative.x * SENSITIVITY)
    camera.rotate_x(-event.relative.y * SENSITIVITY)
    camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-40), deg_to_rad(60))
    func _physics_process(delta):
    # Add the gravity.
    if not is_on_floor():
    velocity.y -= gravity * delta
    # Handle jump.
    if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = JUMP_VELOCITY

    # Handle Sprint
    if Input.is_action_pressed("sprint"):
    speed = SPRINT_SPEED
    else:
    speed = WALK_SPEED
    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    var input_dir = Input.get_vector("left", "right", "up", "down")
    var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
    if is_on_floor():
    if direction:
    velocity.x = direction.x * speed
    velocity.z = direction.z * speed
    else:
    velocity.x = 0.0
    velocity.z = 0.0
    else:
    velocity.x = lerp(velocity.x, direction.x * speed, delta * 2.0)
    velocity.z = lerp(velocity.z, direction.z * speed, delta * 2.0)

    t_bob += delta * velocity.length() * float(is_on_floor())
    camera.transform.origin = _headbob(t_bob)
    move_and_slide()


    func _headbob(time) -> Vector3:
    var pos = Vector3.ZERO
    pos.y = sin(time * BOB_FREQ) * BOB_AMP
    pos.x = cos(time * BOB_FREQ / 2) * BOB_AMP
    return pos

  • @fractalchaos8245
    @fractalchaos8245 4 месяца назад

    amazing tutorial

  • @TheRemaindersYT
    @TheRemaindersYT 8 месяцев назад

    This guy needs more credit!

  • @wertypearl7015
    @wertypearl7015 Месяц назад +2

    This needs an update for 4.3. Completely new to coding/game design and the clamp method for the camera nets me: “Invalid assignment of property or key ‘rotate_x’ with value of type ‘float’ on a base object of ‘Camera3D’. Would defo appreciate a fix for this pls. This is my very first Godot project and I’m using this tutorial for help.

  • @mattg6550
    @mattg6550 Год назад +1

    Is there a reason for walk/sprint values being const? If you wanted to add a speed boost or something would it still make sense to structure this way?

    • @rickymolnar
      @rickymolnar Год назад +3

      Think of the constant values as a base value that everything else builds off of. If you want to add a speed boost, do something like WALK_SPEED * 2.0 to double their speed. Then, when the boost disappears it reverts back to whatever the base speed is.

  • @Dragon20C
    @Dragon20C Год назад

    Looks very cool!

  • @FNDoomIsland
    @FNDoomIsland 11 месяцев назад +1

    6:59 How do you get a forward arrow on keyboard😭💀☠️

  • @FirstLast-lx6iw
    @FirstLast-lx6iw 2 месяца назад

    I'm new to godot but when I click Mesh for 0:40 "Create Simplified Convex Collision Sibling" doesn't appear.

    • @yuriipetrov1593
      @yuriipetrov1593 2 месяца назад

      Hey! I have the same issue too. Did you find out how to resolve it?
      My list of the parameters:
      Create Collision Shape..
      Create Navigation Mesh
      Create Outline Mesh...
      Create Debug Tangents
      View UV1
      View UV2
      Unwrap UV2 for Lightmap/AO
      @LeginGages

    • @binglywingly
      @binglywingly 2 месяца назад +2

      Click on Mesh and then Create Collision Shape, make sure the first option is set to "Sibling" and the second option "Simplified Convex"

  • @thatoneguy6469
    @thatoneguy6469 4 месяца назад +2

    When I got to the head bob part, after finishing the vertical bob, my player goes halfway through the floor, and collisions of objects randomly work, does anyone know what could be happening?

  • @ck88777
    @ck88777 5 месяцев назад +1

    isnt it bad that t_bob increments forever? wont it run into some precision error eventually (theoretically)?
    maybe it doesnt happen in practice

  • @ColdBlueLight
    @ColdBlueLight 11 месяцев назад

    thank you sir i was able to create a juiced up first person controller! and mod it to my likeing!

  • @SunJaycy
    @SunJaycy 10 месяцев назад

    little tip. instead of typing onready etc. drop the node into the script but before dropping it in hold CTRL then release lmb

    • @womp47
      @womp47 9 месяцев назад

      good tip

  • @ryan_isacow21
    @ryan_isacow21 8 месяцев назад

    Thanks a little fast but help understand how godots code works

  • @kartooncrate
    @kartooncrate 26 дней назад

    I am getting a breakpoint error here:
    camera.rotate_y(-event.rotate_x * mouse_sens)
    the error says: "Invalid access to property or key 'rotate_x' on a base object of type 'InputEventMouseMotion'." Any fix?

  • @Ryuko15
    @Ryuko15 10 месяцев назад +2

    my character fall right through the csgBox node, what can i do?

  • @GGfrostZ
    @GGfrostZ 2 месяца назад +1

    Major issue with the headbob. it does not take into account the original Y position of the camera so whenever you stop moving it sticks to whatever value it was at when velocity.length() = 0. Meaning, the camera could be at wildly different heights depending on BOB_AMP.
    EDIT: Here's how you could fix that. Replace this in your _physics_process function:
    if velocity.length() > 0 and direction != Vector3.ZERO:
    t_bob += delta * velocity.length() * float(is_on_floor())
    camera.transform.origin = _headbob(t_bob)
    elif:
    camera.transform.origin = lerp(camera.transform.origin, original_camera_y, delta * 5.0)
    t_bob = 0.0
    You need to define a variable named: original_camera_y. Then you need to put this in your func _ready():
    original_camera_y = camera.transform.origin
    (you can also just set this to a hardcoded float for height like 0.0, but that's all up to you.)

    • @senseiscavern6140
      @senseiscavern6140 Месяц назад

      i exactly copied this code but shows a indentation error Expected conditional expression after "elif".