Smooth Up & Down Stair Handling | Godot 4 FPS Controller Tutorial

  Рет қаралды 2,878

Majikayo Games

Majikayo Games

Күн бұрын

The third video of a series where we will build an FPS game. This video shows how to implement smooth up & down stair handling.
Full Playlist: • Godot FPS Tutorial
GitHub Repo: github.com/majikayogames/Simp...
CSGStairMaker3D scene which you can use in your own projects (CC0/public domain): github.com/majikayogames/Simp...
All source code and included assets are licensed under the CC0/public domain license.
Contents of this video:
0:00 - Intro
0:45 - Simple method
1:37 - Final result preview
1:51 - CSGStairMaker3D
2:22 - Add 2 Raycast3Ds to your CharacterBody3D
3:53 - Utility functions setup
8:44 - Add variables
10:09 - Snapping player down to stairs
17:01 - Snapping player up to stairs
24:07 - Camera smoothing
29:12 - Final result and outro
If this tutorial helped you, consider supporting the channel on Patreon or Ko-fi:
/ majikayogames
ko-fi.com/majikayogames

Пікірлер: 50
@MajikayoGames
@MajikayoGames 29 күн бұрын
*NOTE/CORRECTION:* Someone pointed this out to me, but there can be a case where you can't jump when running up stairs. Also if you use velocity.y += jump_velocity for your jump instead of velocity.y = jump_velocity, it can cause you to stick to the stairs charging up your y velocity to go flying after. I added this small fix to check if velocity.y > 0 before snapping up stairs which ensures the character won't snap up the stairs if jumping & walking forward. You can incorporate this fix into your stair code as well: github.com/majikayogames/SimpleFPSController/commit/ba3499cb6eda147175a141391276b2976428dfd7
@wukerplank
@wukerplank Ай бұрын
Your tutorials have so much substance! Not one of those "how to get started", but "how to get something polished". Thank you for putting these together!
@MajikayoGames
@MajikayoGames Ай бұрын
Appreciate the comment from a returning viewer 😄😄Glad I can keep making content you enjoy and find useful. More to come soon.
@nick12791
@nick12791 Ай бұрын
Can I say thank you honestly there aren't many tutorials on this and I hope you keep adding to this controller. I'm also so glad you keep it simple and not using 100's of scripts using state machines third party plugins etc which yes are good, but at the same time if you are just trying to learn one part you are hunting through the video trying to understand the part they are typing and if it's using things from other scripts this is perfect for people that want to learn how these problems are tackled and solved. ❤❤❤❤
@MajikayoGames
@MajikayoGames Ай бұрын
Appreciate the comment :) Indeed I will be adding a bunch more features I'm going to add to this character controller. Going to release a bunch more videos very soon on it, probably in the next few days.
@Darmanarnar
@Darmanarnar 3 күн бұрын
excellent tutorial I appreciate that you take time to show documentation and do more show than tell.
@PastaMaster115
@PastaMaster115 24 күн бұрын
Here is a tip if your downstairs movement is working but upstairs is not. CHECK SPELLING. I was trying everything to figure out why I couldn't go up. I misspelled "CSGShape3D" in the class check. I spelled it "CGSShape3D". Just in case someone is having the same problem.
@possiblyzslot838
@possiblyzslot838 21 күн бұрын
Hell yeah! Your original was a great solution, but now it's even better!
@MajikayoGames
@MajikayoGames 21 күн бұрын
thank you :D I like your profile picture
@Boildroid
@Boildroid Ай бұрын
nice job. I use shapecast for step checking. And I give up on using Physics test. Positioning of shapecast or raycast is important if you want to add crouch
@tomasz9429
@tomasz9429 Ай бұрын
Delicious, solved my problem of unintentional ledge grabbing on jump. Thank you for sharing your knowledge, very appreciated. Another step taken in my new hobby of fiddling with coding.
@footnotesforthefuture3300
@footnotesforthefuture3300 Ай бұрын
Always love seeing the ways people dive into character controllers. Consider that with your single raycast you cannot walk backwards upstairs, or strafe upstairs. An alternative method is to do three "move and slides." i.e. get "wish" direction, then move the player up, then along the wish direction, then down. You have to then potentially revert that movement if you didn't hit anything. (while I'm commenting - I also want to add that I hate capsule colliders because when you walk near the edge of objects you sort of fall off but no really. counter strike uses a box collider I believe)
@MajikayoGames
@MajikayoGames Ай бұрын
Ah do they? I was actually trying to find what collider shape is used in CSS but I couldn't find anything. I also find that annoying about the capsule shape lol. Also - the raycast is rotated later in the code so it will allow walking up stairs. The method you described is basically what I do here I think, I run a body test motion in front at the expected pos next frame based on velocity, and slightly above, shooting downward. If it collides at feet safely on a flat surface (that's what the raycast checks) character will be moved there.
@footnotesforthefuture3300
@footnotesforthefuture3300 Ай бұрын
​@@MajikayoGames Oh very nice. Obviously I skipped around in the video :'). Yes I think you're basically doing what I suggested. Maybe also consider a shapecast instead of a raycast. Will be following!
@yuyu-zs6jb
@yuyu-zs6jb Ай бұрын
Quality content. Thank you!
@futursoup9007
@futursoup9007 Ай бұрын
thank you mate 🙏
@Creeperassasin-nc5wk
@Creeperassasin-nc5wk Ай бұрын
YOU ARE A SAINT
@GeekROS
@GeekROS Ай бұрын
This is a fantastic series of courses that I've learned a lot from. I hope the author can add a tutorial about foot joints and slopes, aimed at preventing the feet from exceeding the model when a character walks on a slope and allowing them to align with the slope's angle. I believe many people need this; it's probably called IK (Inverse Kinematics).
@MajikayoGames
@MajikayoGames Ай бұрын
Glad to hear! I'm also interested in IK/procedural animation. I'll write that down as a potential video topic.
@Morimea
@Morimea Ай бұрын
Thanks for sharing!
@deathsyrup
@deathsyrup Ай бұрын
love it!
@MajikayoGames
@MajikayoGames Ай бұрын
Thank you :)!
@nataliereilly7895
@nataliereilly7895 Ай бұрын
💪🏼
@meanwhile_0
@meanwhile_0 Ай бұрын
This is a really nice implementation, though I am contending with some jitter in my project due to the CameraSmooth node following the CharacterBody3D up/down the step before snapping back to perform its move_towards() function in the next frame. I've experimented with changing the delta around, but to no avail. Any ideas?
@MajikayoGames
@MajikayoGames Ай бұрын
The camera smooth function should be called as the last thing in the physics process, after either stair up/down snap function has been called. If you put it before, that would mean it would snap back the frame after we already moved & rendered the frame to the screen, likely resulting in jitter. So _slide_camera_smooth_back_to_origin should be called every physics process frame after everything is done. If that is what you mean by performing move_towards next frame.
@PastaMaster115
@PastaMaster115 24 күн бұрын
So, I got up and down movement to work just fine with one small issue. I'm still flying off the stairs sometimes going down. Not every time but every 1/10 times. And it's usually when sprinting. Maybe the check isn't fast enough to catch when you go too fast?
@MajikayoGames
@MajikayoGames 24 күн бұрын
you might try increasing the length of the stairs below raycast3d. i think i had this problem, i noticed extremely rarely i could bounce off stairs. worst that will happen if it's too long is slight jitter stepping off some things.
@PastaMaster115
@PastaMaster115 23 күн бұрын
@@MajikayoGames I tried to change it to -1m instead of -0.75 and it stopped working altogether. I soon realized I changed it to 1 instead of -1 and I felt dumb. It works every time now. lol
@MajikayoGames
@MajikayoGames 23 күн бұрын
@@PastaMaster115 happens to the best of us :)
@DEATHTRUTH
@DEATHTRUTH 22 күн бұрын
Your solution is really clever and works great, though I had a couple of issues; If your movement speed is too slow it is not able to snap up the stairs and starts jittering up and down. I think this is because the translation distance is not sufficient enough at such a small velocity and the capsule simply slides back down, at least for my capsule size (radius of 0.2m). Is there a way to add a minimum velocity clamp to the expected_move_motion function? The other issue i encountered was the camera smooth would have it's position moved on the z and x axis's when going down the stairs. Adding move toward code similar to the y axis solved this, but I was wondering if you or anyone else had this issue?
@MajikayoGames
@MajikayoGames 22 күн бұрын
for the first part, you might try using a box shape instead of a capsule. i was thinking about switching my character controller to use a box instead, because of this issue where you can kind of be half on the floor sliding off it. if when walking up the stairs the character stops you can get caught slowly sliding down an edge like this and not technically be 'on floor'. for the camera smooth, im not sure what you mean. i have mine set up so it only ever drifts it along the y axis. this makes sense to me because the horizontal speed is constant going up/down stairs as it is moving on floor. so just always move with character xz. also less glitchy with headbob that way from some testing i noticed.
@DEATHTRUTH
@DEATHTRUTH 20 күн бұрын
@@MajikayoGames Thanks for the reply, what I ended up doing was removing the camera smoothing all together an instead interpolate my characters position between the steps instead. multiplying the interpolation speed by the step height and move speed also helped. Applying this technique to the snap down too. And of course switching to a box collider too :)
@porkyorcy1715
@porkyorcy1715 25 күн бұрын
When I press jump after going up or down stairs gravity is no longer being applied and I just float instead, how do I fix this :(?
@MajikayoGames
@MajikayoGames 24 күн бұрын
Can't think of why this would happen. Do you mean you fly up in the air? Check my pinned comment, it may be due to y velocity accumulating when sticking to stairs. Just make sure you are not calling snap up stairs if y velocity is positive
@porkyorcy1715
@porkyorcy1715 24 күн бұрын
@MajikayoGames Thx for the quick response! I don't get flung upwards, it's if I press jump I go up and don't come back down, I just float 😭 it only happens after going up or down stairs, the jumping works before then
@MajikayoGames
@MajikayoGames 24 күн бұрын
@@porkyorcy1715 i cannot imagine why that's happening. if you want to pastebin your character script i could take a look.
@porkyorcy1715
@porkyorcy1715 24 күн бұрын
@MajikayoGames idk if youtube lets me post links in comments, i sent u it on twitter 😈🙏
@mrjshzk
@mrjshzk Ай бұрын
does this only work for players? can it work on an npc (nav agent) controlled?
@MajikayoGames
@MajikayoGames Ай бұрын
Interesting question, right now I'm focusing on just doing a player script, but just as CSS has bots which will move by the same laws of physics & rules as the normal players, we could adapt this to be used for a bot script. For that, we would basically just simulate the player input. We might have to abstract the input layer a bit more, so the bot can essentially send fake inputs, depending on some navigational AI. I think the movement wouldn't be that hard, as we already have wish_dir variables which are just set to input. Instead of keyboard input, we would just look to the nav agent's instructions for the wished move direction. I'll write this down as an idea for a future tutorial as this could be pretty interesting I think. Thanks :)
@MajikayoGames
@MajikayoGames Ай бұрын
Oh also, I realized you probably mean allowing bots to walk down stairs specifically. I haven't looked into that exactly, I would have to look into how navmesh works. If using godot's built in version, it would probably take some fine tuning, but I would think you would bake the nav mesh with the agent_max_climb set to the same height/slightly great than the max step height of your player. And it might take some tuning but I'm guessing something like above would work.
@mrjshzk
@mrjshzk Ай бұрын
@@MajikayoGames yes, I'm trying a solution like yours and using the NPC's velocity as the direction, but no luck yet maybe I'm doing something wrong
@mrjshzk
@mrjshzk Ай бұрын
@@MajikayoGames Yeah been having quite some difficulty figuring out all the navregion properties to create the perfect navmesh that can handle stairs (with non ramp collision) and and holes like doors and such. I think if you made a tutorial for it would be a fun (and maybe somewhat frustating xD) challenge and it would definitely be the only one on YT.
@MajikayoGames
@MajikayoGames Ай бұрын
@@mrjshzk added it to my list of tutorial ideas :) i do like doing unique videos as they seem to get the most views. No competition i guess if im the only one making a video on a particular topic. I would probably be doing it a bit later in the series as i have a lot more tutorials to get through though
@AntonioRColon
@AntonioRColon 19 күн бұрын
This is an incredible and exceptionally well-explained solution! Thank you so very much, MajikayoGames. I'm ecstatic to have completed this great tutorial and I can't wait to see what else you've got and what's coming next.
@MajikayoGames
@MajikayoGames 18 күн бұрын
Appreciate your comment :D glad you enjoyed!
Crouch + Sourcelike Crouch Jump | Godot 4 FPS Controller Tutorial
19:23
Making an FPS Weapon Manager in Godot 4
23:08
Chaff Games
Рет қаралды 22 М.
Final muy increíble 😱
00:46
Juan De Dios Pantoja 2
Рет қаралды 20 МЛН
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,8 МЛН
PINK STEERING STEERING CAR
00:31
Levsob
Рет қаралды 22 МЛН
Water Movement  + Visual Effect | Godot 4 FPS Controller Tutorial
15:54
How Godot's Transform3D Type Works
24:16
Majikayo Games
Рет қаралды 690
Mirrors, Every Way You Can Make Them In A Video Game
8:14
Code It All
Рет қаралды 52 М.
Immersive Sim in Godot 4: COGITO - Overview
8:22
Philip D
Рет қаралды 31 М.
Godot Has A New Global Illumination System ...Again
11:48
Gamefromscratch
Рет қаралды 41 М.
This is one of my favorite video game exploits
3:27
Garbaj
Рет қаралды 241 М.
Optimization Tutorial: OCCLUSION CULLING in Godot
8:29
Zenva
Рет қаралды 1,6 М.
I Made a Desktop Pet in Godot
16:02
RachelfTech
Рет қаралды 62 М.
Why Stairs Suck in Games... and why they don't have to
11:24
Nick Maltbie
Рет қаралды 1,5 МЛН
Final muy increíble 😱
00:46
Juan De Dios Pantoja 2
Рет қаралды 20 МЛН