How To Code An FPS Controller In Godot 3

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

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

  • @VickylanceMedia
    @VickylanceMedia 2 года назад +23

    Line number 22 and 24 can be further simplified as follows,
    Input.get_axis("left", "right"), 0, Input.get_axis("forward", "backward")

    • @NagiDev
      @NagiDev  2 года назад +8

      Oh right, I forgot about that! Thank you so much! You're awesome!

    • @harukills
      @harukills 2 года назад

      Oh wow

    • @harukills
      @harukills 2 года назад +2

      What does that 0 mean?

    • @NagiDev
      @NagiDev  2 года назад +1

      The function get_axis(negative, positive) would be used to set the input Vector3. Since, we will be controlling the velocity along y through gravity, we don't need any input for that.
      So, we'll set it to 0.

    • @harukills
      @harukills 2 года назад

      @@NagiDev ah alr

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

    defiantly the easiest tutorial yet on RUclips about Godot 3d fps movement thank you so much.

  • @davidphillips9366
    @davidphillips9366 2 года назад +22

    Great tutorial! There is definitely a lack of 3D Godot content and this was clear and very well done! You should consider making a video on how to set up a simple level like this one.

    • @NeZversSounds
      @NeZversSounds 2 года назад +2

      Lack of what content? What have you searched for?

    • @davidphillips9366
      @davidphillips9366 2 года назад

      @@NeZversSounds In my experience its been far easier to find clear cut beginner tutorials for 2D content in Godot.

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

    I LOVE that you made this specific video. When making an FPS it's the foundation for your character and it's very appreciated.
    I took notes on all of the code and now have a baseline to reference to for any upcoming FPS projects!

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

    Your tutorial is easy to understand and it immediately worked for me first try, unlike other times i've used tutorials and struggled to make them work. Thanks a lot, Nagi!

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

      Hi! In case you're using Godot 4, I've posted a new video specifically for making an FPS controller in Godot 4. Be sure to check it out if you want!
      Also, I'm glad I could help!

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

    Hi! Thank you for your tutorial! It's short but very informative (which is great since I've needed it in like 5 min before deadline)

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

    Thank you so much! I have been struggling to find tutorials on this topic, but this one actually worked

  • @mouseroot8053
    @mouseroot8053 2 года назад +2

    Awesome video, I was very easily able to add sprinting to this script.

  • @diegodelacerda8828
    @diegodelacerda8828 2 года назад +2

    absolutely great tutorial. I really hope you make more!

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

    Dude! You're a Legend👑for this!✨👌

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

    Thanks for this! Was really easy to add bob and stuff with sine

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

    Man, new sub.
    You explained it so well

  • @indieology7336
    @indieology7336 2 года назад +5

    This is a really great tutorial! Thank you! Maybe a third person animated controller next?

    • @NagiDev
      @NagiDev  2 года назад +3

      I believe Johnny Rouddro does a great job of explaining that, but if I feel the need for an updated tutorial, I'll surely make one. Stay tuned!

  • @BAGG-b1o
    @BAGG-b1o 3 месяца назад +2

    When I implemented the gravity, there was an error that was that it couldn't convert Vector3 to float:
    velocity.x = lerp(velocity.x, MoveDir * speed, accel * delta)
    velocity.z = lerp(velocity.z, MoveDir * speed, accel * delta)
    velocity = move_and_slide(velocity, Vector3.UP)
    what did I do wrong?

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

      What version of Godot are you using?

    • @BAGG-b1o
      @BAGG-b1o 3 месяца назад

      @@NagiDev 3.5

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

      You didn't write .x and .z after MoveDir.
      You code should look like:
      velocity.x = lerp(velocity.x, MoveDir.x * speed, accel * delta)
      velocity.z = lerp(velocity.z, MoveDir.z * speed, accel * delta)

    • @BAGG-b1o
      @BAGG-b1o 3 месяца назад

      @@NagiDev Thank you so much 😁

  • @magundah14
    @magundah14 2 года назад +2

    great tutorial!

  • @BernardoLumiert
    @BernardoLumiert 2 года назад +3

    i want to learn how to code without logic nodes, it's being a pain in the ass, thanks for this tutorial! (suggestion: explain more about script terms for newbies like me, example what is Vector3 and what does it means, and why you need to put a .ZERO after, avoiding people to google these stuff)

    • @NagiDev
      @NagiDev  2 года назад +1

      I understand. My videos are more geared towards intermediate Godot developers. I'm planning on doing Godot 4 tutorials next and will be focussing it for Godot beginners. I hope it'll help you! Stay tuned!

  • @pierrenagonio
    @pierrenagonio 2 года назад +2

    Enjoyed. +SUB! waiting for more, like movement camera, like in Dark souls games. THX Friend!

  • @theforgottenfoold3555
    @theforgottenfoold3555 2 года назад +4

    Awesome!!!!

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

    This is good. We need more 😅

  • @ClaudioCavalcanteTonha
    @ClaudioCavalcanteTonha 2 года назад +2

    u are the best!

  • @MadManTnT
    @MadManTnT 2 года назад +6

    Please make more :D

    • @NagiDev
      @NagiDev  2 года назад +1

      I did :3

    • @MadManTnT
      @MadManTnT 2 года назад +2

      @@NagiDev i know. great presentation. i can't wait for next video.

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

    Hi Nagi,
    First of all, great content. I'm fairly new to Godot and quickly learned that its fanbase(users) is fairly small still. I followed along with your tutorial and everything seems great. The only thing I am struggling with is that when I move with a/w/d/s respectively, they seem to be stuck to the initial direction of the 3-dimensional space. Let me rephrase: I would like to know if there would be a way to make the W always go forward respectively to the camera view for instance, or is this a bad/dumb practice? Would love to hear something back. I am using your tutorials for an art school project! :)

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

      Hey N P,
      If you mean to say you want the player to always move along the global axis when pressing the key, not taking the camera rotation into the calculation. Then, all you need to do is skip the .rotated() call. We're using the .rotated() function call to convert the input direction (which is in global coordinates) into the player's local coordinates.

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

      If you ever got stuck on this, I believe what you might have done is accidentally put "head." before your rotation_degrees.y, which locks the movement directions to the cardinal directions rather than reactive to the camera.

  • @mohammedexe-t1c
    @mohammedexe-t1c Год назад +1

    your the best programmer

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

    I have an issue, The movement is working fine, But When i try to look up or down, It looks like the camera arcs forward and zooms in, I don't know what to do

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

      can you check if the camera is at the position (0, 0, 0) relative to the head node?

  • @ansel569
    @ansel569 2 года назад +2

    for some reason, I have a problem with the jump being consistent. Sometimes it doesn't jump, and I assume it has to do with the is_on_floor check as it works if I don't check that (but then obviously you can infinity jump).

    • @NagiDev
      @NagiDev  2 года назад +2

      Did you set the physics to Godot physics in the project settings? Also, did you pass the vector3.UP in the move and slide function call?

    • @AlexanderTersakian
      @AlexanderTersakian 2 года назад +1

      I had the same problem. I fixed it by changing "is_action_just_pressed" to "is_action_pressed" for "jump". Not sure if this will have any downstream repercussions, but it worked.

    • @NagiDev
      @NagiDev  2 года назад +1

      @@AlexanderTersakian is_action_just_pressed only work on the frame you pressed the button, while is_action_pressed stays true as long as the button is pressed. This means the player will keep jumping as long as you keep the key pressed down.

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

    How did you make the villager look at you?

  • @Blitzer1001
    @Blitzer1001 2 года назад +2

    How do you make it so you can jump infinetly? bc an character can fly in an game i am working on

    • @NagiDev
      @NagiDev  2 года назад

      For that you can define a flag variable (a variable that's either true or false) and toggle it anytime you want to fly

    • @Warionator
      @Warionator 2 года назад

      for the jump logic, just remove the face they have to be on the floor to jump, only when they press jump

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

    ❤❤❤

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

    Love U ❤♥❤

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

    Uh when I tried doing the gravity part, I ran the game and then I fell right through the floor. I tried making the floor very thick but it still made me fall right through. Could you help me?

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

      Is the floor a StaticBody with a CollisionShape child?
      If so, does the collision layer / mask for both the player and the floor have any layer in common?

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

      @@NagiDev I made the floor a csgbox.

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

      @@listed7568 did you enable collisions from the inspector?

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

      @@NagiDev Oh. It works now I turned it on lol

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

    I am getting the error too many arguments for move_and_slide expected 0 but got 1

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

      You are probably using Godot 4. This tutorial is for Godot 3.

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

      @@NagiDev do you know how to fix

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

      You could use Godot 3.5. Or you could wait for me to post a tutorial for Godot 4.0 explaining everything in detail.
      The code required for kinematic body motion has been changed, so you will have to set the value of the in-built variable `velocity` and then call move_and_slide() as is without any parameters.

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

    Soooo For some reason my up down look are inverted and so are my moving forwards and backwards idk why I did everything as u did
    Any help would be appreciated

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

      This could likely be due to accidentally switching up and down in one of the Input functions, or maybe a misplaced +/- ?

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

      @@NagiDev idk I’ve looked over the code a few hundred times but I’ll recheck it (I’m using this code in a passion project)

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

      @@samfrank910 let me know if I can take a look at the code. I'll be glad to help!

  • @merah3527
    @merah3527 2 года назад +1

    how do i fix jump sometimes not being detected

    • @NagiDev
      @NagiDev  2 года назад

      change the physics engine in the project settings to Godot physics

  • @riversonr
    @riversonr 2 года назад

    for some reason it doesn't register is_on_floor() when i'm on the floor, but thinks i'm is_on_wall() instead somehow (even seems to is_on_floor() when my head hits the ceiling)
    what do
    update: now is_on_floor() is just flipping between the two states every frame

    • @NagiDev
      @NagiDev  2 года назад

      I think either the gravity you apply is too low or you're not passing the UP vector in move_and_slide.

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

    Bro it say that in line 3 there is an unexpected identifier in class body and i don't know how to fix it can you pls say the fix and I am also using godot 4

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

      This tutorial is for Godot 3. It won't work on Godot 4

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

      Change it from export to @export that should fix it

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

    so far im putting everything in right but when i open the scene its not working. the the 'head' / camera is a error. its says get_node: (node not found: head ( relative to /root/root/camera2/player) what can i do to fix this ?

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

      Can you check if your player scene has a node called "Head" making sure all capital and small letters match?
      You player scene should be like:
      Player
      -CollisionShape
      -Head
      --Camera
      and your code should have
      onready var head = $Head
      Also, make sure the player script is attached to the Player node. It's common mistake to attach the script to some other node in the scene accidentally. In the scene tree, check if the script icon shows in the Player node. If it's not there you should find the node where the script is attached, remove the script, select the Player node and attach the script to this node.

  • @etfwe
    @etfwe 2 года назад +1

    the map wont show up when i tried it

    • @NagiDev
      @NagiDev  2 года назад

      hi can you please elaborate what issue you're facing?

    • @etfwe
      @etfwe 2 года назад

      @@NagiDev it just doesnt show up, i think i just put it on a different scene and it didnt show because the other was main scene

    • @NagiDev
      @NagiDev  2 года назад

      @@etfwe you can try instancing the map scene on your main scene or set the map scene as the main scene from the project settings.

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

    is there a way to make the camera work with the joystick?

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

      I was going to give you a written answer, but now I think I'll make a tutorial about it.
      But if you want a quick answer, you'll have to add some input_maps with each joystick axis (up, down, left, right) and then do Input.get_vector(). Use this input axis to change the look_rot vector.

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

    I can’t find special node anywhere

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

      Can you please elaborate which special node you're talking about?

  • @ManiaManiacs
    @ManiaManiacs 2 года назад +1

    I dont know why but nothing works
    please help

    • @NagiDev
      @NagiDev  2 года назад +1

      Sure, can you please explain what issue you're facing and what system/Godot version you're working with?

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

    how do i make my own map

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

      There's a bunch of different ways to make a map, for this tutorial I used Blender to create the mesh for the map, exported it as a gltf file and imported it into Godot.
      If you're not familiar with 3D modeling, you can use free assets available online. My recommendation would be Kenny's Assets!

  • @codeimagine6824
    @codeimagine6824 2 года назад +1

    how did you make the overworld

    • @NagiDev
      @NagiDev  2 года назад

      Blender

    • @codeimagine6824
      @codeimagine6824 2 года назад

      That explains why everything broke when tried importing the level

    • @NagiDev
      @NagiDev  2 года назад

      @@codeimagine6824 I don't quite understand. Can you please explain the issue to me?

    • @codeimagine6824
      @codeimagine6824 2 года назад +1

      @@NagiDev i tried copy just the overworld scene into my project being lazy to create my own level
      The materials didn't apply for the models and i got an error saying that the materials used for the level is not found in the original directory from your project
      Also blender and godot really hate me whenever I try to do anything in 3d

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

    I can't move at x axis can someone help

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

      Which Godot version are you using?

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

      3.5

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

      Can you please check if you might've missed or misspelt something in the code?

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

      @@NagiDev it's fine now thanks

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

    WHY IS MY MOUSE STILL showing and still moving]

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

      Which Godot version are you using?

  • @ClaudioCavalcanteTonha
    @ClaudioCavalcanteTonha 2 года назад +1

    is the scenario a single exported object?

    • @NagiDev
      @NagiDev  2 года назад

      I'm not sure what you mean. But the end result is a scene+script that you can use in any of your project

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

    Line 27 and 32 is error

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

      Hey, can you please share what the error says?

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

      ​​@@NagiDev sorry not 27 but 34 and 40

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

      Hey there again, it would be really helpful if you can share the error message instead of the line number

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

      @@NagiDev line 34: Expected statement, found "Indent" instead.

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

      @@NagiDev line 40 Expected end of file.

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

    i treid but it wouldnt work qwq

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

      What version of Godot are you using? What exact issue are you facing? Are they any errors in the console? Please let me know and I'll my best to fix it.

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

    I am not smart enough for this

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

      I feel you. Just keep trying and you'll find it easy in no time. Best wishes!

  • @daan5532
    @daan5532 2 года назад +2

    i get an error. Parse Error: Static constant 'up' not present in built-in type Vector3.
    modules/gdscript/gdscript.cpp:583 - Method failed. well that

    • @daan5532
      @daan5532 2 года назад +1

      nevermind it works, dumb mistake. Great tutorial!

    • @NagiDev
      @NagiDev  2 года назад

      no worries we all make mistakes. Glad I could help!

    • @daan5532
      @daan5532 2 года назад

      @@NagiDev I am making a gun now but the "is_in_group" function is not passing. The enemy is in the group tho. Let me know if you can help.

    • @NagiDev
      @NagiDev  2 года назад

      @Daan I haven't worked much with groups :/
      Although, the way I handle weapons and guns is by setting enemies and weapons to their own collision layers/masks and/or setting the enemy to it's own class and checking if the gun is colliding with the object of the enemy class/collision layer.
      (I think I should make a tutorial about it soon)

    • @daan5532
      @daan5532 2 года назад +1

      @@NagiDev That would be great. Can you tell me how to implement it?

  • @ClaudioCavalcanteTonha
    @ClaudioCavalcanteTonha 2 года назад +1

    I didn't understand why look_rot.y receives value from event.relative.x, and lookrot.x receives value from event.relative.y

    • @NagiDev
      @NagiDev  2 года назад

      event.relative.x gives us the mouse motion along the screen's x axis (horizontal) which should rotate the player along its y axis. Similarly relative y should rotate along player's x axis.