Godot 4.X : Ultimate First Person Controller Tutorial Part 2 ( 2023 )

Поділитися
Вставка
  • Опубліковано 10 сер 2023
  • Consider a Subscription
    Part 1 : • Godot 4.X : Ultimate ...
    Assets : github.com/lukky-nl/FPS-contr...
    Kenney : www.kenney.nl/
    Poly haven : polyhaven.com/hdris
    This is part 2 of a 3 part fps contoller tutorial series!

КОМЕНТАРІ • 197

  • @stegosaurus1299
    @stegosaurus1299 6 місяців тому +34

    3:50 “When we’re walking we’re gonna be walking”
    -21st century philosophers

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

      Bro hes First Lang is not English So Obviously He won't have good grammer

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

      @@bruvidek it's a joke bro, also *grammar

  • @j.o.t.u.n.n
    @j.o.t.u.n.n 7 місяців тому +50

    states 1:43 Free_looking 4:01 sliding 14:50 head bob 29:04

    •  6 місяців тому +1

      Neede This! 😀

    • @toby818
      @toby818 11 днів тому +1

      thanks

  • @user-ur3pm5qe3v
    @user-ur3pm5qe3v 10 місяців тому +32

    So far this is the best fps series for Godot 4 that I have seen. I hope you finish the series. If you get to a point where you add a weapon I would like to learn how to set it up so that the weapon does not clip through objects. These two lessons were so good, you should turn this into a full FPS Godot 4 course.

    • @JB-qc2gp
      @JB-qc2gp 9 місяців тому +5

      That is typically accomplished with setting the weapon to only be rendered through the camera on top of whatever the camera is seeing. The weapon "doesn't" exist in the game world per se and cannot clip through anything. The downside is that when you are face first in a wall, your weapon will look tiny and break the illusion. For more realism, add a separate collision shape or raycast3d (anything that will detect a weapon collision), with that you could let the weapon collision block you from moving it into another object, or you can toggle the weapon to animate closer to the player, within close enough of a distance that you'd not expect the weapon to ever touch the wall with it that close to the body. Think "pointing your gun to the sky" or "angled to the ground in a resting hold".

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

      real, its a great tutorial that explains things at a good speed and he makes sure to add some nice features and stuff like lerp

  • @Theinvalidmusic
    @Theinvalidmusic 11 місяців тому +97

    Amazing. This just keeps getting better. My requests for part 3 (or 4) would be:
    - Leaning (i.e. peeking around a corner)
    - Climbing / mantling / vaulting
    - Camera 'bump' when the player drops to the ground from a height
    Please keep going!

    • @adzee8711
      @adzee8711 11 місяців тому +1

      Yes these functions would be awesome to see being added

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

      yeah I agree!

    • @squarerootof2
      @squarerootof2 10 місяців тому +1

      Also singing, dancing and tweaking.

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

      Leaning would in theroy be easy it would be similar to crouching. a toggle state where ur collider titlts left and right

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

      what about twearking

  • @SamuTheFrog
    @SamuTheFrog 4 місяці тому +4

    Dude these tutorials are fucking bomb. So concise & straight to the point. Explaining things but not overexplaining or mentioning unnecessary details.
    You a good teacher dog.

  • @LarsOksendal
    @LarsOksendal 11 місяців тому +7

    1. Free-look, rotate head in local space - x and y with lerp.
    2. Weapon handling. Primary, Secondary. Bindings, scroll menu ect.
    Keep up the good work.

  • @_anbh0143
    @_anbh0143 11 місяців тому +5

    wow man thanks a lot !! 10 min into it and already learning a lot !!

  • @funlabsdesignstudio
    @funlabsdesignstudio 2 місяці тому

    So good! Definitely fun to create and play around with. Onto Part 3! Thanks for everything! Can't wait to keep playing around with Godot after completing your 3rd part and see what I can come up with using my art 😁. Been something I have wanted to do for god knows how long.

  • @slav0001
    @slav0001 11 місяців тому +1

    Super video dude, keep it up. You gonna easily hit 100k subs ngl. Thank you for doing the tutorials !

  • @LimaTheBeamer
    @LimaTheBeamer 7 місяців тому

    Love it, amazing tutorial!
    Thank you very much!🫶🏽

  • @Tribune12345
    @Tribune12345 7 місяців тому +7

    Thanks!

  • @dannyjunanazar2106
    @dannyjunanazar2106 11 місяців тому +4

    Thank you for this series. You teach a lot in a simple way. A video on how to create a grabbling gun to swing around like Spider-Men would be awesome. Definitely keep up the good work. I wish you all the best and thank you for the knowledge you share with us.

  • @user-wn9vu6nz4k
    @user-wn9vu6nz4k 11 днів тому

    From my experience with ue5 and unity, this video would be a lifesaver if there were any gamedev tutorials of this quality. Godot has an awesome community.

  • @aryanarayanan4680
    @aryanarayanan4680 11 місяців тому +1

    i like your videos so much, helps me a lot, you are supposed to have a lot more subscribers and views than now

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

    This is mindblowingly incredible.

  • @b0t_nz8
    @b0t_nz8 11 місяців тому +9

    Next some parkour system like vaulting, climbing

    • @n41sd
      @n41sd 11 місяців тому +2

      Oh pls @Lukky this will be amazing!

  • @Snapper-gaming
    @Snapper-gaming 4 місяці тому

    Thats a really cool way to head bob. Good job :)

  • @zarbon6319
    @zarbon6319 6 місяців тому

    thanks for the video , changing !ray_cast_3d.is_scale_disabled was way better than is_colliding , made crouching feels smooth and not keeps crouching in depth everytime i press Ctrl

  • @Quacker24
    @Quacker24 Місяць тому +3

    Since no one wanted to do this, I will. Here is the script bois. (This also includes controller controls but you can easly remove that by removing the const joystick_sens = 3 variable and deleting the Joystick Motion Looking Logic function)
    extends CharacterBody3D
    # Player Nodes
    @onready var head = $nek/head
    @onready var standing_collision_shape = $standing_collision_shape
    @onready var crouching_collision_shape = $crouching_collision_shape
    @onready var ray_cast_3d = $RayCast3D
    @onready var nek = $nek
    @onready var camera_3d = $nek/head/eyes/Camera3D
    @onready var eyes = $nek/head/eyes
    # Speed Variables
    var current_speed = 5.0
    const walking_speed = 5.0
    const sprinting_speed = 8.0
    const crouching_speed = 2.0
    # States
    var walking = false
    var sprinting = false
    var crouching = false
    var free_looking = false
    var sliding = false
    # Slide Variables
    var slide_timer = 0.0
    var slide_timer_max = 1.3
    var slide_vector = Vector2.ZERO
    var slide_speed = 10.0
    # Head Bobbing Variables
    const head_bobbing_sprinting_speed = 22.0
    const head_bobbing_walking_speed = 14.0
    const head_bobbing_crouching_speed = 10.0
    const head_bobbing_sprinting_intensity = 0.2
    const head_bobbing_walking_intensity = 0.1
    const head_bobbing_crouching_intensity = 0.05
    var head_bobbing_vector = Vector2.ZERO
    var head_bobbing_index = 0.0
    var head_bobbing_current_intensity = 0.0
    # Movement Variables
    var crouching_depth = -0.5
    const jump_velocity = 4.5
    var lerp_speed = 10.0
    var free_look_tilt_amount = 8
    # Input Variables
    var direction = Vector3.ZERO
    const mouse_sens = 0.3
    const joystick_sens = 3
    # Get the gravity from the project settings to be synced with RigidBody nodes.
    var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
    # Mouse Lock
    func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
    # Mouse Motion Looking Logic
    func _input(event):
    if event is InputEventMouseMotion:
    if free_looking:
    nek.rotate_x(deg_to_rad(-event .relative.y * mouse_sens))
    nek.rotation.y = clamp(nek.rotation.y, deg_to_rad(-120), deg_to_rad(120))
    else:
    rotate_y(deg_to_rad(-event .relative.x * mouse_sens))
    head.rotate_x(deg_to_rad(-event .relative.y * mouse_sens))
    head.rotation.x = clamp(head.rotation.x, deg_to_rad(-80), deg_to_rad(80))
    # Joystick Motion Looking Logic
    func _process(delta):
    var input_dir = Input.get_vector("look left", "look right", "look up", "look down")
    if free_looking:
    nek.rotate_y(deg_to_rad(-input_dir.x * joystick_sens))
    nek.rotation.y = clamp(nek.rotation.y, deg_to_rad(-120), deg_to_rad(120))
    else:
    rotate_y(deg_to_rad(-input_dir.x * joystick_sens))
    head.rotate_x(deg_to_rad(-input_dir.y * joystick_sens))
    head.rotation.x = clamp(head.rotation.x, deg_to_rad(-80), deg_to_rad(80))
    func _physics_process(delta):
    # Movement Input
    var input_dir = Input.get_vector("left", "right", "forward", "backward")
    # Handle Movement States
    # Crouching
    if Input.is_action_pressed("crouch") || sliding:
    current_speed = crouching_speed
    head.position.y = lerp(head.position.y,crouching_depth,delta*lerp_speed)
    standing_collision_shape.disabled = true
    crouching_collision_shape.disabled = false
    # Slide Begin Logic
    if sprinting && input_dir != Vector2.ZERO:
    sliding = true
    slide_timer = slide_timer_max
    slide_vector = input_dir
    free_looking = true
    print("Slide Begin")
    walking = false
    sprinting = false
    crouching = true
    elif !ray_cast_3d.is_colliding():
    # Standing Logic
    standing_collision_shape.disabled = false
    crouching_collision_shape.disabled = true
    head.position.y = lerp(head.position.y,0.0,delta*lerp_speed)
    if Input.is_action_pressed("sprint"):
    # Sprinting Logic
    current_speed = sprinting_speed
    walking = false
    sprinting = true
    crouching = false
    else:
    # Walking Logic
    current_speed = walking_speed
    walking = true
    sprinting = false
    crouching = false
    # Handle Free Looking
    if Input.is_action_pressed("free_look") || sliding:
    free_looking = true
    if sliding:
    camera_3d.rotation.z = lerp(camera_3d.rotation.z,-deg_to_rad(10.0),delta*lerp_speed)
    else:
    camera_3d.rotation.z = -deg_to_rad(nek.rotation.y*free_look_tilt_amount)
    else:
    free_looking = false
    nek.rotation.y = lerp(nek.rotation.y,0.0,delta*lerp_speed)
    camera_3d.rotation.z = lerp(camera_3d.rotation.z,0.0,delta*lerp_speed)
    # Handle Sliding
    if sliding:
    slide_timer -= delta
    if slide_timer

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

    thankyou for this tutorial

  • @nieraraqel
    @nieraraqel 11 місяців тому

    Hello, very helpful tutorial!

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

    Best tutorial ever!

  • @CapybaraStudios
    @CapybaraStudios 6 місяців тому +3

    Thanks for the great tutorial! One thing I fixed is jumping whille under objects. you can fix this by moving the jump function under the raycast check.

    • @AntonioRColon
      @AntonioRColon 6 місяців тому +2

      That's a great solution! I resolved mine by making it so the player can't jump if "is_crouching && is_on_floor()", but yours maintains the improved movement versatility of the original controller. I'll give it a try.

  • @NobodyHere539
    @NobodyHere539 7 місяців тому

    Thank you very much! ❤

  • @elmano1202
    @elmano1202 11 місяців тому +1

    Thank you so much for these tutorials, this looks really tight and polished!

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

    great video.

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

    thank you so much

  • @akitaris326
    @akitaris326 2 місяці тому

    for anyone wondering about infinite sliding glitch or sliding in air, add this to physics process delta and a few vars, this edits some of the code in the video, but this method works. There is a nuance with the slide cooldown never actually reaching 0, but it functions as intended.
    var slide_cooldown = 5.0
    var can_slide = false
    func _physics_process(delta):
    slide_cooldown = clamp(5.0, 0, 5.0)
    # Getting movement inputs
    if sliding == true:
    slide_cooldown -= 1.0
    if sprinting && input_dir != Vector2.ZERO && slide_cooldown == 5.0:
    sliding = true
    free_looking = true
    slide_timer = slide_timer_max
    slide_vector = input_dir

    walking = false
    sprinting = true
    crouching = true
    if not is_on_floor():
    velocity.y -= gravity * delta
    slide_timer = 0.0
    can_slide = false
    # Handle jumping
    if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = jump_velocity
    jumping = true
    sliding = false
    can_slide = false
    animation_player.play("jump")

    if jumping:
    can_slide = false
    crouching = true
    jumping = true

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

      idk man still sliding infinately , thanks for trying to fix it tho

  • @informatiqueisfutur-ve2ro
    @informatiqueisfutur-ve2ro 5 годин тому

    this is the best tutorial i found keep going and you will hit 1 milion subscribes plus if you finished the tutorial and add a weapon and a grappling gun then you have karlson but in godot

  • @nyx1284
    @nyx1284 10 місяців тому +7

    if someone doesnt want to implement free look and still want still wants to look around during a slide. Then what you'd wanna do is
    that if your sliding rotate your neck and if not rotate the player body as such:
    if(sliding):
    neck.rotate_y(-deg_to_rad(event.relative.x *sens))
    else:
    rotate_y(-deg_to_rad(event.relative.x *sens))
    and when the sliding ends you would want to add the rotation of the neck to the player rotation and then reset the neck rotation like this
    if(slide_timer < 0.0):
    sliding = false
    self.rotation.y += neck.rotation.y
    neck.rotation.y = 0.0
    so now after a slide you will immediately start moving in the direction your looking if your pressing WASD.
    This worked for me and if you find any bugs or issues feel free to tell me.

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

      hi, thanks alot! only one thing, my code gives me an error saying event is not declared in the current scope. do u have any idea where ive gone wrong?

    • @Delta79G
      @Delta79G 7 місяців тому

      @@xih0o Hi, don't know if it's still relevant for you, but the
      if(sliding):
      neck.rotate_y(-deg_to_rad(event.relative.x *sens))
      else:
      rotate_y(-deg_to_rad(event.relative.x *sens))
      part has to go on the mouse look logic. Without clamping, it should look something like this:
      func _input(event):
      #Mouse look logic
      if event is InputEventMouseMotion:
      if sliding:
      neck.rotate_y(deg_to_rad(-event.relative.x*mouse_sens))
      else:
      rotate_y(deg_to_rad(-event.relative.x * mouse_sens))
      head.rotate_x(deg_to_rad(-event.relative.y * mouse_sens))
      head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))

  • @DerpyNinjaFrog
    @DerpyNinjaFrog 11 місяців тому +8

    Multiplying the lerp factor by delta does not make it frame-independent btw (it is a fine approximation with high enough framerates though). To make lerp frame-independent, the factor needs to be 1.0 - pow(0.5, delta * lerp_speed). I don't have much experience with making lerp frame-independent, so feel free to correct me if I'm wrong. (I just watched the Jonas Tyroller video on delta time)

    • @limax2107
      @limax2107 9 місяців тому +2

      Thank you very much bro.

  • @user-pz9ju6ss7r
    @user-pz9ju6ss7r 2 місяці тому

    21:34 - the call to the move_toward function can be safely removed, because the flow of the program does not get there, because the direction variable always has a value, since we ourselves pass the value to it every tick... and since we have the lerp function we don't need the move_toward function any way
    24:07 - instead of these characters we can write "or" or "and"
    25:39 - for the same effect, we can change the minimum value for the timer (instead of zero, set it to 0.1, for example)
    39:35 - no need to place parentheses here
    -- using a capslock for constants is a standard practice that helps you immediately determine whether you are dealing with mutable data or not

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

    It is the Coolest!!!

  • @Mr_Poole
    @Mr_Poole 10 місяців тому +2

    I was racking my brain on how to get the camera not to bob since I didn't want to include jumping in my particular controller. I found that instead of 'if is_on_floor() && !sliding' instead, I just used 'if input_dir != Vector2.ZERO:' et voila.

  • @lopsidedpolygon
    @lopsidedpolygon 11 місяців тому +3

    🎉 yay 🎉

  • @basilhsxatzhkostas2800
    @basilhsxatzhkostas2800 11 місяців тому +1

    Something that has to do with parkour would be great. Maybe wall jumping? or wall running. Stuff like that could turn out to be great

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

    very nice for gdscript its preferred to use or instead of || though for there style guide but great stuff man

  • @XaviXaviXavi
    @XaviXaviXavi 6 місяців тому

    Thank you for this amazing tutorial, if the player spam sliding it gives a higher speed, perhaps we could block the sliding for a second or two after each uses.

    • @AntonioRColon
      @AntonioRColon 6 місяців тому

      I recommend using the same "slider_timer" logic utilized in the video, but instead making it a "can_slide_timer" paired alongside a "can_slide" bool that has to be equal to 0.0 before being set to true and then can be utilized again. It's a great way to add cooldown state logic to abilities such as the time length between individual gun shots in an FPS or cooldown timers for player abilities.

    • @user-pz9ju6ss7r
      @user-pz9ju6ss7r 2 місяці тому

      I made the sliding speed less than the running speed, so sliding is useful only when you need to quickly hide under something or overcome a low obstacle that you cannot jump over

  • @MrJoono
    @MrJoono 10 місяців тому +1

    Hi, thanks a lot for this tutorial, it's the best I've found so far!
    I've added the possibility to crawl. It's working except I can press crouch when crawling in a small space and the character goes into crouching position, clipping through the collider. I'll be interested to see how you'll implement it.
    Anyway, I'm waiting for Part 3, keep it up!

    • @bonsaipropaganda
      @bonsaipropaganda 10 місяців тому +4

      you probably need to do the same thing you did for crouching -> standing. Basically have your raycast first check if it's colliding and if it's safe to get up. :)

  • @blunderer-hd7gr
    @blunderer-hd7gr 11 місяців тому +1

    I like

  • @sockbomb6802
    @sockbomb6802 11 місяців тому +1

    Please add a mantling/ledge climbing system in the next video!

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

    This training course is very cool, but there are a couple of bugs that I found. This is a continuation of sliding even if you hit the wall and sliding in the air (after jumping). You can also add somersaults in the future. And so thank you for the training materials, they are very cool and comprehensive!

    • @bondo532
      @bondo532 10 місяців тому +1

      not sure about how you would fix sliding after running into a wall but to make it so that you can't slide in the air when checking conditions for slide add a condition ''and is_on_floor()" and that should make it so that guys cant slide in air

    • @StealthAim
      @StealthAim 9 місяців тому +2

      For stopping a slide when you hit a wall you could make a raycast going forward and if it hits a object set the sliding to false similar to how we could not stop crouching if we were under a object

  • @savakujundzic
    @savakujundzic 11 місяців тому +1

    can you make a tutorial on making a grappling hook for a fps game?

  • @SHEKOTASHKA
    @SHEKOTASHKA 8 місяців тому

    hello! many thanks for the video - very affordable and high-quality material. I am a complete beginner, I did everything like you - but instead of smoothly shaking the camera left and right, it shakes as if sharply and in the center, and not to the sides like you - tell me how to fix it?

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

    39:07

  • @Asonc1
    @Asonc1 6 місяців тому

    QOL:
    i added !ray_cast_3d.is_colliding() to the jump thing so you dont jump when the raycast is colliding , idk makes it smoother to me (since i kinda ruined the crouching collision shape to make crouch jumping a thing( crouch jump makes you able to get on surfaces that are a bit high for normal jump :3)

    • @therealpancake7140
      @therealpancake7140 6 місяців тому

      I think you can achieve the same by just having a standing collider and scaling it for when you need to crouch. I tried doing it that way and when it scaled it does so towards the center of the capsule which will lift your "feet" up a little bit. This means when you jump and crouch you'll gain some extra height and you essentially have one less collider to handle which is always a win. Note that you will fall through the ground sometimes lol you'll need to tweak the position of the player after they stand up again

  • @user-qm2zg6rj9m
    @user-qm2zg6rj9m 5 місяців тому

    Amazing tutorial love them, one thing i would like to know.
    is that how states are supposed to be ? it doesn't feel right i have seen some videos where the State design pattern isn't used like this at all.

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

    Part 3 please

  • @s3nju279
    @s3nju279 8 місяців тому

    i wish theyd fix the subview port problem so the gun can receive shadows.

  • @karasuZanu
    @karasuZanu 6 місяців тому +1

    when i crouching and under the box, i tried jumping and i see other side. must i writing condition code or is there any settings for better physical action? maybe not need crouching if i under a thing for seen the other side.

  • @xX_GAMER_SEXUAL_Xx
    @xX_GAMER_SEXUAL_Xx 10 місяців тому +1

    Can u make a vault that makes you slide over an object?

  • @mcbride967
    @mcbride967 6 місяців тому +2

    I'm following along in C# but I condensed the movement state a bit to an enum:
    private enum MovementState
    {
    Idle,
    Walking,
    Sprinting,
    Crouching,
    FreeLooking,
    Sliding
    }
    private MovementState _currentMovementState = MovementState.Idle;
    private void SetMovementState(MovementState movementState)
    {
    _currentMovementState = movementState;
    }

    • @asdfghjkl-jk6mu
      @asdfghjkl-jk6mu 5 місяців тому

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

      Enums also exist in GDScript, not sure why they weren't used in the video.

  • @mrcannibalhunter526
    @mrcannibalhunter526 Місяць тому +1

    Is the headbobbing suppose to be happening when I'm not moving?

  • @Doronoss
    @Doronoss 9 місяців тому +1

    instead of having many booleans that cannot be true together (you either crouch/sprint/walk/run) just make an enum
    enum MovementState {CROUCH, SPRINT, WALK, RUN}
    then add
    MovementState currentMovementState = MovementState.WALK (for the default settings)
    And then when you want to add a freelook to the mix you can also either define it as a bool (if u don't have other look modes) or create another enum for CameraMode
    enum CameraMode {FirstPerson,ThirdPerson,TopDown,FreeLook ,etc....}
    and then to make switch cases to handle each one of those mode.
    Since the script isn't that big at the moment and the functionality is very basic this practice is better, however, if things get more complicated I'd even give up the enums, and make those states that inherit a BaseState and manage all of those via a state machine.

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

      What?

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

      ​@@Mark6O9 Look for StateMachine pattern, there are free EBooks about it. Better practice, easier to expand. I don't know how to answer to "What?", if you have concrete question about the design I proposed (that is much better and much faster to code) feel free to ask.

    • @BrunoHiltune
      @BrunoHiltune 8 місяців тому

      @@Doronoss Hi, what exactly do you mean by "then add MovementState currentMovementState..."? I don't really understand where you would add this comment, and where you're pulling the currentMovementState var from in this case. Do you mean just creating a var currentMovementState and use that? Thanks in advance

    • @Doronoss
      @Doronoss 8 місяців тому

      @@BrunoHiltune Yes, you create one variable that is of an enum type, instead of managing many booleans. It is adviced to do so when the booleans cannot be true simultaneously.

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

    How would you do a lean for shooting around corners or peeking?

  • @WoyaThePug
    @WoyaThePug 6 місяців тому

    Would it be possible to separate the video into chapters so we could select timestamps? Such as for free-looking, sliding, etc.

  • @mrmaniac9905
    @mrmaniac9905 11 місяців тому

    blu3 i'm watching you

  • @NolanDye
    @NolanDye 6 місяців тому +1

    Has anyone else hit a brick wall with clamp? My camera is still entirely disregarding the head clamp code

  • @ceejaytwoyoshi8536
    @ceejaytwoyoshi8536 8 місяців тому

    so I've been experiencing this odd bug where if I slide, the camera can't clamp itself to a certain angle anymore. When I look fully downwards or upwards, it just flips my view and makes my player character all wonky, and I don't exactly know what's going on.
    here's my code. it's slightly different from the tutorial but yeah
    extends CharacterBody3D
    const WSPEED = 5.0
    const SSPEED = 7.5
    const CSPEED = 3.0
    const JUMP_VELOCITY = 4.5
    var playerFOV = 100
    const FOVCHANGE = 1.5
    @onready var currentSpeed = WSPEED
    # Get the gravity from the project settings to be synced with RigidBody nodes.
    var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
    @onready var neck = $Neck
    @onready var head = $Neck/Head
    @onready var camera_3d = $Neck/Head/Camera3D
    @onready var collision_shape_standing = $CollisionShape_STANDING
    @onready var collision_shape_crouching = $CollisionShape_CROUCHING
    @onready var head_checker = $Neck/Head/HeadChecker
    @onready var slope_checker = $SlopeChecker
    var mouseSens = 0.15
    var camAngl = 0.0
    var targetAngl = 0.0
    var viewRollAmnt = 1
    var viewRollSpeed = 0.1
    const DEFAULT_HEIGHT = 2.0
    const CROUCH_HEIGHT = 1.0
    var crouchSpeed = 10
    var crouchDepth = -0.75
    var slideTime = 0.0
    var slideTimeMax = 1.5
    var slideVec = Vector2.ZERO
    var direction = Vector3.ZERO
    enum CharacterStates { IDLE, WALKING, JUMPING, FALLING, SPRINTING, CROUCHING, SLIDING }
    var currentState = CharacterStates.IDLE
    var stateNames = {
    CharacterStates.IDLE: "IDLE",
    CharacterStates.WALKING: "WALKING",
    CharacterStates.JUMPING: "JUMPING",
    CharacterStates.FALLING: "FALLING",
    CharacterStates.SPRINTING: "SPRINTING",
    CharacterStates.CROUCHING: "CROUCHING",
    CharacterStates.SLIDING: "SLIDING"
    }
    func _ready():
    Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
    func _input(event):
    if event is InputEventMouseMotion:
    head.rotate_x(deg_to_rad(-event.relative.y * mouseSens))
    head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))
    if currentState == CharacterStates.SLIDING:
    neck.rotate_y(deg_to_rad(-event.relative.x * mouseSens))
    else:
    rotate_y(deg_to_rad(-event.relative.x * mouseSens))
    func _physics_process(delta):
    var input_dir = Input.get_vector("left", "right", "forward", "backward")
    head.rotation.z = lerp(head.rotation.z, 0.0, delta * 8.0)
    head.position.y = lerp(head.position.y, 1.5, delta * 8.0)
    collision_shape_standing.disabled = false
    collision_shape_crouching.disabled = true
    match currentState:
    CharacterStates.IDLE:
    if is_on_floor():
    velocity.x = 0.0
    velocity.z = 0.0
    if direction.length() > 0.5:
    currentState = CharacterStates.WALKING
    else:
    currentState = CharacterStates.IDLE
    if Input.is_action_pressed("crouch"):
    currentState = CharacterStates.CROUCHING
    if Input.is_action_just_pressed("ui_accept"):
    currentState = CharacterStates.JUMPING
    else:
    currentState = CharacterStates.FALLING
    CharacterStates.WALKING:
    if is_on_floor():
    currentSpeed = WSPEED
    if direction.length() > 0.5:
    currentState = CharacterStates.WALKING
    else:
    currentState = CharacterStates.IDLE
    if Input.is_action_pressed("sprint") and (!input_dir == Vector2.DOWN and input_dir.x == 0):
    currentState = CharacterStates.SPRINTING
    if Input.is_action_just_pressed("ui_accept"):
    currentState = CharacterStates.JUMPING
    if Input.is_action_pressed("crouch"):
    currentState = CharacterStates.CROUCHING
    else:
    currentState = CharacterStates.FALLING
    CharacterStates.CROUCHING:
    if is_on_floor():
    currentSpeed = CSPEED
    head.position.y = lerp(head.position.y, 1.5 + crouchDepth, delta * 8.0)
    collision_shape_standing.disabled = true
    collision_shape_crouching.disabled = false
    if Input.is_action_just_pressed("ui_accept"):
    currentState = CharacterStates.JUMPING
    if Input.is_action_just_released("crouch") and !head_checker.is_colliding():
    if direction.length() > 0.5:
    currentState = CharacterStates.WALKING
    if direction.length() 0.5:
    currentSpeed = SSPEED
    if Input.is_action_just_released("sprint"):
    if direction.length() > 0.5:
    currentState = CharacterStates.WALKING
    if direction.length()

  • @teamkraken1620
    @teamkraken1620 11 місяців тому

    if i have 1000 requests i'll spend all of them on vaulting and peeking

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

    When you added the slide tilt at 28:00 it removed the free looking feature when you are standing and walking, was this my mistake or is there a way to bring free looking back after you add the slide tilt?

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

    adding || sliding at 24:40 made it so my character will slide infinitely. I'm not sure how to fix this. sliding = false doesn't necessarily prevent the player from sliding so long as you hold the crouch button, but in my case you lose control of your movement and can't stop sliding. I think it's due to the fact that the code continuously sets the slide_timer to 1.0 so it never ends. I removed || sliding, but my character can slide so long as you hold down crouch.

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

      I found a solution. Btw, I'm using godot 4.2.2.stable.mono I moved some code to make sure the physics function checks to see if we are sliding before checking to see if we are hitting the crouch button, this prevents looping and reseting the slider_timer to max every frame.

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

    This tutorial works beautifully. Thank you, Lukky!
    Two quick tips for coding newbies having issues.
    - Check and recheck all of your code comparative to the code provided within the video. Pause often. Something as small as a + instead of * can have massive ramifications on how your code will function. (Happened to me...)
    Rewrite the entire line if necessary. As it can often help you pick up what you missed writing the first time without even realizing it. (Which also happened to me...)
    - Order of operation is significantly important!! Code is read in a hierarchy so your code structure order is VERY important to perform properly!! If your code isn't functioning, chances are it could be where it's located in your script. Copy the EXACT location structure of the video if you want to get the exact same results as Lukky.
    I hope these tips help others. Please stop posting your broken code. And happy coding!

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

    i am facing a problem. if i slide when pressed sprint then crouch, my sliding does not end, it just sliding until i fell off the floor

  • @bluepower48
    @bluepower48 8 місяців тому

    i have a slight issue with the end of the slide its like the lerp doesn't work

  • @Le_Tigero
    @Le_Tigero 4 місяці тому +1

    the head bobbing part doesnt work for me for some reason

  • @batartpictures
    @batartpictures 8 місяців тому

    For some reason I can't jump while running forward, but CAN jump while running left, right, or even backwards. Any idea where this would come from ? Searched everywhere without luck

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

    Hi, is normal that when we are in "free looking", the move of the player get inverted? i mean, to put it one way, i have to move forward with "a and d" and on the sides with "w and s".

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

    Btw i did this in part 1 is putting the player in a scene that i put in my level scene okay to do with this script?

  • @Avarage_degenerate
    @Avarage_degenerate 6 місяців тому

    15:01 sliding

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

    what to do for 151 im getting invalid get index 'rotation' (on base: 'null instance')

  • @snaildad193
    @snaildad193 3 місяці тому

    Hey Lukky, I'm trying to add footstep audio to this character controller and I'm having trouble finding a way to do it. My idea is that the computer is already generating the sinewave, right? So why not set it to play a footstep sound whenever the sinewave reaches its lowest point? That way, I can adjust the headbob to be as aggressive as I want without fear that I might break the timing of the footsteps. Thank you for the tutorial, I love your videos!

    • @snaildad193
      @snaildad193 3 місяці тому

      Nevermind I figured it out!

    • @jamess.9930
      @jamess.9930 2 місяці тому

      @@snaildad193 How did you do it??? I am running into this issue too.

    • @snaildad193
      @snaildad193 2 місяці тому

      @@jamess.9930 I'm taking a break with game design because I lost the ssd with my installation of Godot on it (along with a bunch of other stuff) so I can't tell you exactly what code I used but I remember it being something like
      if head_bob_vector.y < 0:
      footstepplayer.play
      That might not work out of the box, but I remember it being really easy. Just make a 3D audio player, attach it to the camera (not the head, specifically the camera, otherwise the footstep sounds are going to do a weird thing). Grab a footstep sound off of Kenney or something and throw it in there, set the var footstepplayer = AudioPlayer3D or whatever, and then play around with the values until you get it to work. This is definitely just a bandaid solution and I'm 100% sure you can do better, but hopefully this can get you into the right ballpark. Sorry I couldn't be of more help!

  • @pineapplegoomba7123
    @pineapplegoomba7123 2 місяці тому

    is it just me or when you are doing the free look clamp when you press the button you can't move your camera

  • @_Dynxmo_
    @_Dynxmo_ 8 місяців тому

    i need the player script can anyone help?? the sliding isn't working and every code is the same as shown in the video

  • @matheusbuzatti9161
    @matheusbuzatti9161 11 місяців тому +1

    Next put animations 3d character please

  • @lonegamedevlongjourneyman
    @lonegamedevlongjourneyman 6 місяців тому

    i cant seem to get the print("slidegein) and (slide end) idk what's hapeniing is the && method outdated am using godot 4.2.1

  • @cucubob9535
    @cucubob9535 3 місяці тому

    how i can i make so u can only slide forward

  • @tessytocaliente
    @tessytocaliente 9 місяців тому +4

    @Lukky i have a bug, if you slide and continue pressing sprint, crouching and W it going to slide forever and the timer won't actually work, can you help me with that?

    • @j.o.t.u.n.n
      @j.o.t.u.n.n 7 місяців тому

      i don't thing we will get a fix for this a lot have the same problem

    • @gderuki
      @gderuki 5 місяців тому +1

      A workaround:
      reset `sprinting` to false (right after overriding a `direction` variable, which located just before "if direction:" check)

  • @reinaldojunior573
    @reinaldojunior573 9 місяців тому +1

    hi lukky and hey guys, I have a doubt. So when my character slide it goes just to 1 side, specifically to the right, does anybody know what can I do?
    Amazing tutorial bro, I love your videos, keep going!

    • @AntonioRColon
      @AntonioRColon 6 місяців тому

      Hey, rein. Don't have doubts! Trust in Lukky! And more importantly trust in yourself!
      I wanted to have the character shift tilt angles as well based on the neck rotation angle during slide. So here is my script modification if you still need help with this. As well as for anyone else interested in the additional feature too.
      if sliding:
      # Check if neck rotation.y is below 0.0. Lean right.
      if neck.rotation.y < 0.0:
      camera_3d.rotation.z = lerp(camera_3d.rotation.z, -deg_to_rad(5.0), delta * lerp_speed)
      # Check if neck rotation.y is above 0.0. Lean left.
      elif neck.rotation.y > 0.0:
      camera_3d.rotation.z = lerp(camera_3d.rotation.z, deg_to_rad(5.0), delta * lerp_speed)
      else:
      camera_3d.rotation.z = -deg_to_rad(neck.rotation.y * free_look_tilt_amount)
      I hope this meets your needs. Happy coding!

  • @MUIzViper
    @MUIzViper 6 місяців тому

    On 21:00 i have the same code as it does on the video and it says "Invalid optands "basis" and "Vector3" for "+" operator." Please help i dont know what this means
    Please I still don't know what I'm doing here

  • @onennon3942
    @onennon3942 7 місяців тому +3

    How can I get the headbobbing code to work without the sliding or free looking? For some reason I can't get any headbobbing effects, and I also get an error saying "input_dir" is not declared.

    • @JanDeBondt
      @JanDeBondt 23 години тому

      it's probably because the input_dir declaration is below that line that gives the error. Reorganize your code a bit and it will work :)

  • @kennethrapp1379
    @kennethrapp1379 11 місяців тому +1

    Integrate a 3d model, and gun with sights.
    Also (related) switching from first to second person

  • @dennis3
    @dennis3 11 місяців тому

    please add first person swimming, there aren't many tutorials for 3D

  • @jamesreed361
    @jamesreed361 7 місяців тому +1

    When I add the "OR" Logic to the Free looking if statement it appears that my slide does not end. Not sure where I went wrong with the code, anyone have an idea? I I have the free_looking set to false in the slide end logic but it just continues sliding with no end. Is there anyway the completed code could be shared on github so I can try and find the error?

    • @j.o.t.u.n.n
      @j.o.t.u.n.n 7 місяців тому

      i have the same problem i can also continue sprinting when crouched

  • @NexSilverMinecraft
    @NexSilverMinecraft 11 місяців тому +2

    Hey lukky
    This is a fabulous tutorial I have seen for Godot fps but,I found a bug that when I jump and slide it slides in mid-air can you fix this bug I have tried to fix it but I failed
    Thank😊

    • @lukky.
      @lukky.  11 місяців тому +4

      Yes! In your jump function add "sliding = false". You can cancel the slide anytime by setting the slide state to false.

    • @AntonioRColon
      @AntonioRColon 5 місяців тому +3

      Bug... Or bonus feature!!! I personally love it!

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

      @@AntonioRColon 🤣🤣

  • @FullBitGamer
    @FullBitGamer 3 місяці тому

    SO when I put "if Input.is_action_pressed("crouch") || sliding:" it makes the slide last forever...
    and it doesn't seem like the code to use the slide's "delta" works since it just goes on forever if you hold SPRINT + CROUCH

    • @user-pz9ju6ss7r
      @user-pz9ju6ss7r 2 місяці тому

      I changed "Input.is_action_pressed()" to "Input.is_action_just_pressed()"

    • @akitaris326
      @akitaris326 2 місяці тому

      I got you man, add this into the code
      var slide_cooldown = 5.0
      var can_slide = false
      func _physics_process(delta):
      slide_cooldown = clamp(5.0, 0, 5.0)
      # Getting movement inputs
      if sliding == true:
      slide_cooldown -= 1.0
      if sprinting && input_dir != Vector2.ZERO && slide_cooldown == 5.0:
      sliding = true
      free_looking = true
      slide_timer = slide_timer_max
      slide_vector = input_dir

      walking = false
      sprinting = true
      crouching = true
      if not is_on_floor():
      velocity.y -= gravity * delta
      slide_timer = 0.0
      can_slide = false
      # Handle jumping
      if Input.is_action_just_pressed("jump") and is_on_floor():
      velocity.y = jump_velocity
      jumping = true
      sliding = false
      can_slide = false
      animation_player.play("jump")

      if jumping:
      can_slide = false
      crouching = true
      jumping = true

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

    why he only has 7.9k subs

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

    so far a amazing tutorial. but i have some problems now i cant seem to fix. i left sliding out because i didnt want that. so i moved on with the head bobbeling. followed allong till the end of the video. and wen i tested the head bobbeling nothing happend. i cant get the head bobbeling to work. overlooked the code a couple of times but nothing is missing.... anybody some tipps ?

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

      So i found the Problem. My Head bobbing code was Not in Line with The Rest of the Code. I Fixed that and now Head bobbing is working.

  • @Phosphor_screen.
    @Phosphor_screen. 4 місяці тому

    37:08 This is so every side to side movement we go up and down twice *Starts moving mouse.......................................................................................

  • @ElMigol_
    @ElMigol_ 8 місяців тому

    26:43 Does this actually work for anyone? I followed the tutorial perfectly (checked like 5 times already) and my character doesn't seem to save the sliding momentum. It just switches to walking speed when it's in the air.

    • @j.o.t.u.n.n
      @j.o.t.u.n.n 7 місяців тому

      check your var slide_speed he change it to 10.0. my charactor runs when crouched and keeps slideing if Ctrl is held down does your do the same .

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

    My headbob isn't working, I tried to fix it but only positions the camera a little to the right while moving and there it freezes

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

      Did you found a fix ? I can't get my Head Bob to Work either. Wrote the whole Code but it didnt Work for some reason...

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

      @@mcpaper90d66 Probably not helpful for oyu anymore but in case any one else finds this. The problem (in my case at least) was with "head_bob_index += HEAD_BOB_SPRINT_SPEED * delta" I had it just "=" instead of "+="

  • @detonate53
    @detonate53 11 місяців тому

    wallrunning?

  • @robotboy5026
    @robotboy5026 7 місяців тому +1

    Ive been trying to get the sliding to work for hours and i Have no idea what I've done wrong lol

  • @dynstinn
    @dynstinn 9 місяців тому +1

    i have a bug where the clamp function is not clamping the x rotation of the camera

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

      me too, and I don't know how to fix it

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

      @@justitsandrey2692 my previous build was perfectly fine but suddenly it breaks for the new versions. I don’t understand. Beforehand it’s fine but now in the editor it just doesn’t work

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

      same, any fixes ?
      @@dynstinn

    • @Arze_ae
      @Arze_ae 7 місяців тому

      @@justitsandrey2692 heres the code
      head.rotation.x = clamp(head.rotation.x,deg_to_rad(-90),deg_to_rad(90))
      It worked fine for me I hope this helps you out

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

    Sliding does not work for me. I checked it multiple times and still can't find an issue

    • @diycheese4238
      @diycheese4238 3 місяці тому

      5 months late, but me too, did you ever figure it out?

  • @revenant131
    @revenant131 9 місяців тому +1

    Regarding move states. Everything below the "elif" is indented, is going to cause issues when trying to add more move states? I wanted to add a walk state to move slower but this breaks sprinting as if its being captured within the if statement.
    I am pretty new to coding but how would I get around this?
    Using dashes to represent indents.
    Crouching
    -Sliding
    elif
    -walk(I named this default)
    - -Sprint
    -then my walk state

  • @myfriendchowdari
    @myfriendchowdari 11 місяців тому

    Can you add wallrunning plz

  • @lonegamedevlongjourneyman
    @lonegamedevlongjourneyman 6 місяців тому

    well the video betrayed me at 19:00 when i tried to test print ("slide") idk why

    • @DemolishCentral
      @DemolishCentral 5 місяців тому +1

      Neither did I probably some indent issue.
      I restarted it from scratch and rewrote the code, it worked on my second try.

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

      @@DemolishCentral yeah same thing for me as well i traced back what i did and i figured out what i was doing wrong great tutorial definitly

  • @MonkeyWrench28
    @MonkeyWrench28 2 місяці тому

    for some reason i just keep sliding, no clue why. i've gone over the code a thousand times but i can't find anything wrong with it.

    • @akitaris326
      @akitaris326 2 місяці тому

      I got you fam, add this into your code.
      var slide_cooldown = 5.0
      var can_slide = false
      func _physics_process(delta):
      slide_cooldown = clamp(5.0, 0, 5.0)
      # Getting movement inputs
      if sliding == true:
      slide_cooldown -= 1.0
      if sprinting && input_dir != Vector2.ZERO && slide_cooldown == 5.0:
      sliding = true
      free_looking = true
      slide_timer = slide_timer_max
      slide_vector = input_dir

      walking = false
      sprinting = true
      crouching = true
      if not is_on_floor():
      velocity.y -= gravity * delta
      slide_timer = 0.0
      can_slide = false
      # Handle jumping
      if Input.is_action_just_pressed("jump") and is_on_floor():
      velocity.y = jump_velocity
      jumping = true
      sliding = false
      can_slide = false
      animation_player.play("jump")

      if jumping:
      can_slide = false
      crouching = true
      jumping = true

    • @MonkeyWrench28
      @MonkeyWrench28 2 місяці тому

      You're a massive help dude, thanks!

  • @bamb00zld
    @bamb00zld 8 місяців тому +1

    Honestly wish you had made all these features like looking over your shoulder and tilting your head when you're sliding into an optional 4th video. The only game I recall in recent memory that lets you look over your shoulder while moving is an open world survival game (DayZ). You can do it in Apex but what you're making is more for parkour style games...not many games let you slide around and slide under obstacles...not most big budget shooters at least.
    This tutorial series is very helpful, but if you're aiming to help beginner programmers, then start with what every basic person would want in their basic FPS first.
    Also, respect people's time. If you frequently make typos or accidentally check the wrong box, make a note of that, go back and edit those typos out later.

    • @brainbandaid5802
      @brainbandaid5802 7 місяців тому

      I think those typos are actually helpful! I caught one on my own thinking I'd made a mistake and when I fixed it I better understood what the code was doing.