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!
3:50 “When we’re walking we’re gonna be walking”
-21st century philosophers
Bro hes First Lang is not English So Obviously He won't have good grammer
@@bruvidek it's a joke bro, also *grammar
states 1:43 Free_looking 4:01 sliding 14:50 head bob 29:04
Neede This! 😀
thanks
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.
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".
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
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!
Yes these functions would be awesome to see being added
yeah I agree!
Also singing, dancing and tweaking.
Leaning would in theroy be easy it would be similar to crouching. a toggle state where ur collider titlts left and right
what about twearking
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.
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.
wow man thanks a lot !! 10 min into it and already learning a lot !!
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.
Super video dude, keep it up. You gonna easily hit 100k subs ngl. Thank you for doing the tutorials !
Love it, amazing tutorial!
Thank you very much!🫶🏽
Thanks!
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.
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.
i like your videos so much, helps me a lot, you are supposed to have a lot more subscribers and views than now
This is mindblowingly incredible.
Next some parkour system like vaulting, climbing
Oh pls @Lukky this will be amazing!
Thats a really cool way to head bob. Good job :)
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
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
thankyou for this tutorial
Hello, very helpful tutorial!
Best tutorial ever!
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.
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.
Thank you very much! ❤
Thank you so much for these tutorials, this looks really tight and polished!
great video.
thank you so much
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
idk man still sliding infinately , thanks for trying to fix it tho
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
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.
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?
@@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))
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)
Thank you very much bro.
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
It is the Coolest!!!
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.
🎉 yay 🎉
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
very nice for gdscript its preferred to use or instead of || though for there style guide but great stuff man
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.
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.
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
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!
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. :)
I like
Please add a mantling/ledge climbing system in the next video!
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!
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
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
can you make a tutorial on making a grappling hook for a fps game?
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?
39:07
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)
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
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.
no usually states are enums
Part 3 please
i wish theyd fix the subview port problem so the gun can receive shadows.
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.
Can u make a vault that makes you slide over an object?
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;
}
Enums also exist in GDScript, not sure why they weren't used in the video.
Is the headbobbing suppose to be happening when I'm not moving?
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.
What?
@@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.
@@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
@@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.
How would you do a lean for shooting around corners or peeking?
Would it be possible to separate the video into chapters so we could select timestamps? Such as for free-looking, sliding, etc.
blu3 i'm watching you
Has anyone else hit a brick wall with clamp? My camera is still entirely disregarding the head clamp code
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()
if i have 1000 requests i'll spend all of them on vaulting and peeking
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?
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.
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.
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!
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
i have a slight issue with the end of the slide its like the lerp doesn't work
the head bobbing part doesnt work for me for some reason
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
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".
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?
15:01 sliding
what to do for 151 im getting invalid get index 'rotation' (on base: 'null instance')
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!
Nevermind I figured it out!
@@snaildad193 How did you do it??? I am running into this issue too.
@@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!
is it just me or when you are doing the free look clamp when you press the button you can't move your camera
i need the player script can anyone help?? the sliding isn't working and every code is the same as shown in the video
Next put animations 3d character please
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
how i can i make so u can only slide forward
@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?
i don't thing we will get a fix for this a lot have the same problem
A workaround:
reset `sprinting` to false (right after overriding a `direction` variable, which located just before "if direction:" check)
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!
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!
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
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.
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 :)
Integrate a 3d model, and gun with sights.
Also (related) switching from first to second person
please add first person swimming, there aren't many tutorials for 3D
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?
i have the same problem i can also continue sprinting when crouched
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😊
Yes! In your jump function add "sliding = false". You can cancel the slide anytime by setting the slide state to false.
Bug... Or bonus feature!!! I personally love it!
@@AntonioRColon 🤣🤣
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
I changed "Input.is_action_pressed()" to "Input.is_action_just_pressed()"
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
why he only has 7.9k subs
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 ?
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.
37:08 This is so every side to side movement we go up and down twice *Starts moving mouse.......................................................................................
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.
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 .
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
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...
@@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 "+="
wallrunning?
Ive been trying to get the sliding to work for hours and i Have no idea what I've done wrong lol
did you figure it out?
cuz i need help with that too
i have a bug where the clamp function is not clamping the x rotation of the camera
me too, and I don't know how to fix it
@@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
same, any fixes ?
@@dynstinn
@@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
Sliding does not work for me. I checked it multiple times and still can't find an issue
5 months late, but me too, did you ever figure it out?
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
Can you add wallrunning plz
Also a dash would be useful
well the video betrayed me at 19:00 when i tried to test print ("slide") idk why
Neither did I probably some indent issue.
I restarted it from scratch and rewrote the code, it worked on my second try.
@@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
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.
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
You're a massive help dude, thanks!
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.
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.