Тёмный

Tutorial: First Person Movement In Godot 4 

Bramwell
Подписаться 18 тыс.
Просмотров 142 тыс.
50% 1

Godot 4 Is all new and exciting, so here's a beginners guide to get up and running with a first person controller in only a couple lines of code!
🔗 Code link: gist.github.com/bramreth/2a62...
📰 Check out my Godot 4 course here! bramwell.itch.io/godot-4-begi...
✨ Socials ✨
🐦 Twitter: / bramreth
💬 Discord: / discord
☕ Buy me a coffee: www.buymeacoffee.com/bram
🎮Games: bramwell.itch.io/
🕺TikTok: / bramreth
🤖 The ninth alpha release for Godot 4 I used in the video is here:
downloads.tuxfamily.org/godot...
Chapters:
00:00 Making the floor
01:41 Creating the player body
03:35 Adding a first person Camera
05:20 Adding a WorldEnvironment
06:47 Making the player move
07:50 Using custom inputs
09:40 Creating the camera script
16:05 Orienting motion to the camera direction
17:36 Other Godot 4 educational material
#Godot4 #GodotEngine #Gamedev

Опубликовано:

 

21 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 389   
@justcnoon
@justcnoon Год назад
deg2rad() has been renamed to deg_to_rad() in Alpha 15, if anybody's having an error.
@mustafamohamud5212
@mustafamohamud5212 Год назад
thank you!
@wordrc
@wordrc Год назад
thanks!!
@wellhellotherekyle
@wellhellotherekyle Год назад
You're a life saver!
@NirielWinx
@NirielWinx Год назад
Good. That 2 was cringey as hell :D
@jameswashington4704
@jameswashington4704 Год назад
@@NirielWinx no it wasnt u mf I will fight u
@wellhellotherekyle
@wellhellotherekyle Год назад
So two things had changed since this video was published... 1. The _unhandled_input part, the code should read like this now: _unhandled_input(event): (All the stuff after on that line in Branwell's code is no longer necessary) 2. deg2rad() has been renamed to deg_to_rad() (Thank you to Andy Reed for pointing this one out) Thanks for the wonderful tutorial Bramwell!
@mando1570
@mando1570 Год назад
thank you so much my guy your comment really helped me ❤
@gustaafmilzink
@gustaafmilzink Год назад
Thank you!
@recker7017
@recker7017 Год назад
point 1 is invalid, typehints never were necessary
@Micahtmusic
@Micahtmusic Год назад
maybe not necessary, but definitely polite
@sechmascm
@sechmascm Год назад
The other stuff on that line improves performance by a huge margin. The engine doesn't have to guess what everyting is supposed to be and it runs those operations faster. If you want a good game, it is necessary.
@alechussak3750
@alechussak3750 Год назад
set_mouse_mode() and get_mouse_mode() have been removed since this video was made. You can now get/set the Input.mouse_mode property directly: SET: Input.mouse_mode = Input.MOUSE_MODE_CAPTURED GET: if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
@gregoriodelimaalves6862
@gregoriodelimaalves6862 11 месяцев назад
how do I do this properly
@koolgabieboi2816
@koolgabieboi2816 10 месяцев назад
please provide a code example
@StephenCodess
@StephenCodess 8 месяцев назад
thanks!
@NerdWithABeard
@NerdWithABeard 7 месяцев назад
This, along with the tip for how to access the other command auto-fills, are much appreciated
@351c4v71
@351c4v71 6 месяцев назад
thanks, that was very helpful
@erin1569
@erin1569 Год назад
Btw, if you want to have the same autocomplete as Bramwell at 11:47, you should go to Editor>Editor Settings>Text Editor>Completion>Add type hints
@dabeanie9426
@dabeanie9426 Год назад
TYSMMMMMMM
@trxlly
@trxlly Год назад
Thanks
@mayodiff2245
@mayodiff2245 Год назад
what a legend
@Marandal
@Marandal 8 месяцев назад
Thank you.
@gamesme1
@gamesme1 7 месяцев назад
Bro thanks alot I was scared that's I did wrong
@madphoenix9826
@madphoenix9826 7 месяцев назад
Always nice to find a information dense tutorial for the specific thing you wanna do ^^ Thank you very much!
@kevindean8312
@kevindean8312 Год назад
I am complete noob to Godot and this tutorial was excellent. Easy to follow and loved how you actually explained everything. Thank you!
@user-ht1dc5iw3n
@user-ht1dc5iw3n 3 месяца назад
same
@DEXA_Entertainment
@DEXA_Entertainment 7 месяцев назад
Very on point, short and helpful! Thank you for teaching not only me but a lot of people too. 😊👍
@theaussieninja8176
@theaussieninja8176 9 месяцев назад
thank your Bramwell for these tutorials I love how you go into great depths on everything I wish more tutorials went into such depth
@sweetdog2398
@sweetdog2398 4 месяца назад
A cool thing you can do with this part: var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_backwards") var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction: if is_on_floor(): velocity.x = direction.x * SPEED velocity.z = direction.z * SPEED else: if is_on_floor(): velocity.x = move_toward(velocity.x, 0, SPEED) velocity.z = move_toward(velocity.z, 0, SPEED) is right before the velocity stuff you can add a if is_on_floor so that you cant change directions midair, or you can use an else comman so that you can but its less.
@aullvrch
@aullvrch Год назад
this made me subscribe! By far the most useful and educational vid on this topic I I have seen thus far, with the added bonus of being in godot 4!!
@petethorne5094
@petethorne5094 Год назад
This is absolutely brilliant! I just downloaded the Beta (woo!) and within a few mins I had a player running around my test scene. Bought your course a while back and now that things are getting more stable, I'm going to have to stop avoiding building a game!
@kevindean8312
@kevindean8312 Год назад
So was Godot 3.x not very stable?
@JohnFenlon
@JohnFenlon Год назад
Just started using Godot, very helpful video to get up & running quickly, many thanks 👍
@PAPRPL8
@PAPRPL8 2 года назад
Thanks for the tutorial; found it quite helpful and moved at a pace I found keep up with as a beginner.
@chrisfritz7545
@chrisfritz7545 Год назад
Just wanted to say thanks for sharing your knowledge. Keep making these videos. You have a great way of explaining what you are doing.
@riisezz0
@riisezz0 Год назад
Hey, man. I'm new to Godot and you've really been helping in the transition to Godot 4. I really appreciate you!
@harryudal3115
@harryudal3115 6 месяцев назад
Thank you so much for all the work you have done, this has given me so much help. And I thank you
@swedishgamedev
@swedishgamedev Год назад
Thank you for this very clear tutorial! It helped a bunch!
@wukerplank
@wukerplank Год назад
Very interesting, thank you for putting this together!
@cyphfrix1620
@cyphfrix1620 Год назад
thanks so much bro, your tutorial is very easy to follow and quick
@bluecheese1066
@bluecheese1066 Год назад
Very nice intro to some 3D player basics. Thank you very much!
@pisel5945
@pisel5945 Год назад
thank you i had no idea how to do something in godot because there was always errors, i didnt think that i will succed following the first tutorial that i clicked on
@ViralShorts8303
@ViralShorts8303 Год назад
Hey man thank you so much its working very good and i am very happy!! you just got a Subscriber😉
@chrismelton6935
@chrismelton6935 8 месяцев назад
Thank you! Explained well and straight to the point.
@VGV0
@VGV0 4 месяца назад
thanks, great video! You explained every step. Much appreciated!
@sogimarvaz
@sogimarvaz 10 месяцев назад
Very nice video, thank you so much Bramwell.
@PanIsTrying
@PanIsTrying 5 месяцев назад
Thank you kindly for your help in this tutorial. It made me a subscriber
@emilyallen7912
@emilyallen7912 4 месяца назад
same
@pommefrites
@pommefrites Год назад
Hey, kind of semi-related but this video helped me fix a long-standing issue with the stair catcher in my character controller being offset if my character starts the level rotated at all, which is fine if the player always starts in the same direction with 0,0,0 rotation, but not great if they do, which is most often the case. It has to do with the lines you highlighted around 17:17 and I used a very similar block to calculate the position of the stair catcher ray cast to swing around in the direction of player movement. I then just had to offset it vertically from the neck height to be near the floor and now it works perfectly no matter which direction the player starts in. Anyway, it had been bugging the hell out of me for a whiiiiile, so thanks for your help!
@Phryj
@Phryj 6 месяцев назад
This was a big help, thank you!
@piimae
@piimae Год назад
Exceptionally well done tutorial, straight to the point and just the right amount of explaining of the details of the mechanics. Thank you!
@I_can-t_GAMING
@I_can-t_GAMING 11 месяцев назад
والله انا كنت واقف على ان الشخصية بتخترق الارض لكن دا اكتر فيديو فادني فشكرا جدا 💖💖💖💖❤❤ By God, I was standing on the fact that the character penetrates the ground, but this is the most useful video, so thank you very much
@dairygecko
@dairygecko 5 месяцев назад
thank you so much, i was watching another tutorial and it skipped the part in which the player was created, im a complete newbie, now i can continue the other tutorial (which was about creating a map)
@acedefective2220
@acedefective2220 5 месяцев назад
thank you, this tutorial was very accessible and helpful
@apersimmon
@apersimmon 6 месяцев назад
I applied this to a 3rd person player but it was very useful, thanks!!
@sethwhite4635
@sethwhite4635 2 года назад
Awesome, thanks for the video!
@user-nl6jx4oz7n
@user-nl6jx4oz7n 10 месяцев назад
Thank you bro. I am a boy who need these types of tutorials. LOVE FROM PUNJAB
@BuffHobbit
@BuffHobbit Год назад
16:00 this is all good but does the player body rotate with the neck? so that the head doesn't just spin around while the body is not. So the body is facing the same way we are looking
@wolcamophone4783
@wolcamophone4783 2 года назад
I wish there was a video that really explained how to better understand movement functions tied to kinematic bodies so that you could know exactly what kind of bhopping or air strafing glitches to put in movement fps controllers.
@KyleRassweiler
@KyleRassweiler Год назад
Is it possible to have the CharacterBody3D interact with physics objects?
@ShadowWolf936
@ShadowWolf936 6 месяцев назад
some of the camera script didn't pop up for me like it did for you. anyway i can get the mouse input part?
@TheInfiniteVoid
@TheInfiniteVoid Год назад
what is the arrow in scrip after inputevent and how do i put it there?
@meteroy17
@meteroy17 Год назад
Is there a way to add other functions like interact, running, crouching, and all that?
@toxslix
@toxslix Месяц назад
Thanks alot very useful video much love to ya mate
@BramwellWilliams
@BramwellWilliams Месяц назад
Glad it helped!
@seeranos
@seeranos Год назад
Why do we rotate the neck node for horizontal movement, but the camera itself for vertical movement? Is it because we want the rotation clamped for the camera?
@RivenbladeS
@RivenbladeS 3 месяца назад
why doesnt godot have buttons to instantiate cube plane culinder etc like unity and you have to set the mesh instance yourself?
@Clan_GG
@Clan_GG Год назад
How would I change the mouse for looking to touch screen I currently have If event is InputEventscreendrag: ≤. ≥ input.set
@Drachenbauer
@Drachenbauer Год назад
i didn´t add a neck node, i rotate the whole character around y instead with the mouse, so i just didn´t get the problem of fixed forward direction, that´s described at 16:15. It feels just like a fully functional first person charecter.
@devinpeck6664
@devinpeck6664 10 месяцев назад
Love this! Thank you so much.
@samuellangford6126
@samuellangford6126 10 месяцев назад
something is wrong with my camera.rotate_x(-event.relative.y * 0.01) does it need any nodes?
@odrzuconyromantyk
@odrzuconyromantyk Год назад
Thank you! This one works and is really easy to follow. One question though, how can i make camera clamp on y axis. Tried to replicate code from x axis but nothing works.
@RedCatGD
@RedCatGD 8 месяцев назад
Thanks a lot ! Helped me out a tone ❤
@mr.e4327
@mr.e4327 4 месяца назад
Great tutorial, thanks mate!
@pacobrian7547
@pacobrian7547 Год назад
you are a genius, you solved my problem of collisions
@Will_-it3mh
@Will_-it3mh 7 месяцев назад
if i tlit the camera to the up and down limits it goes haywire and starts spining to the sides. how do i fix that?
@Mineblox-33333
@Mineblox-33333 6 месяцев назад
Where do I put the deg_to_rad() at so then there will be no error?
@idk-gq8tw
@idk-gq8tw 7 месяцев назад
Can someone help, i started the scene and when i try to rotate is freezes and it says kennedy.gd 10 @ _ready(): node not found: "neck/camera3d" (relative to "/root/node3d/characterbody3d").
@Briedisons69
@Briedisons69 11 месяцев назад
get_mouse_mode is not showing up for me is there a new renamed version of it?
@RealJesus
@RealJesus 10 месяцев назад
help everytime i look down/right the poc starts spinning and it's uncontrollable
@mikhaylastovall1770
@mikhaylastovall1770 4 месяца назад
How would I slow down how fast the mouse is moving in game? It's a little to jerky for my preference. (also pls explain it to me like I'm an idiot please and thank you)
@trueblue97
@trueblue97 9 месяцев назад
This is all cool and good, but how do I make camera controls with the right stick on a controller instead of the mouse?
@Rebel_MC2355
@Rebel_MC2355 Год назад
at 12:21 how do you get those lines of code? im typing them in rn and its very annoying
@ois718
@ois718 9 месяцев назад
for func input it doesnt say inputevent void? im on version 4.1
@bleh1186
@bleh1186 Год назад
Some extreme jitteryness while looking and moving, any idea what's going on with this?
@18_leafclover
@18_leafclover Месяц назад
I'm getting an error on lines 20, 21 Identifier camera not declared in the current scope
@Creeg81
@Creeg81 4 месяца назад
i have a problem where when i look up or down, the camera starts spinning around and gets messed up. anyone kjnow how to fix this
@petermuster5734
@petermuster5734 4 месяца назад
Whenever I run it, my camera isnt able to look down somehow and it offsets itself up by a lot
@kirb9166
@kirb9166 9 месяцев назад
12:22 Where did he get this string of code from i dont understand how he got it
@adaml.5355
@adaml.5355 2 года назад
This is an extremely helpful video.
@burntbrownie
@burntbrownie 5 месяцев назад
Anyone know why the playermodel gets frozen sometimes when walking into walls?
@shigsy2630
@shigsy2630 Год назад
I've written the equivalent in C#, which requires a few differences other than the syntax (e.g. you cant directly modify the Rotation properties so need to create a separate Vector3 and set it to the Rotation, then manipulate and clamp that new Vector 3 before setting the Rotation back to the Vector3). This generally works fine but there is one odd behavior... I can't move the mouse and walk at the same time. So I can stand still looking around with the mouse, or I can walk around with the keys, but I can't do both at once. Any ideas? I suspect differences in how C# handles the Input events. If I'm holding W to walk and then move the mouse at the same time, it doesn't appear to be passing an InputEventMouseMotion event to my _UnhandledInput method. It executes the code in that method but not within the "if" that's checking for the InputEventMouseMotion, so presumably the event is something else (like the key im holding down to walk). If I stop moving (let go of W) and move the mouse, it correctly passes the InputEventMouseMotion to the _UnhandledInput method and I can look around fine.
@mrunion
@mrunion Год назад
Care to share your experiment with C#?
@itokuun
@itokuun Год назад
Awesome video man
@PlasmaGhost303
@PlasmaGhost303 2 месяца назад
the tutorial was great! thank you
@explainmydrawing8986
@explainmydrawing8986 Месяц назад
Where should I add the jump animation
@Mrtubb158
@Mrtubb158 9 месяцев назад
How do you get the star icon thing at 13:23
@YOZA.
@YOZA. 8 месяцев назад
extends CharacterBody3D const SPEED = 5.0 const JUMP_VELOCITY = 4.5 # Get the gravity from the project settings to be synced with RigidDynamicBody nodes. var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") @onready var neck := $Neck @onready var camera := $Neck/Camera3d func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseButton: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) elif event.is_action_pressed("ui_cancel"): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: if event is InputEventMouseMotion: neck.rotate_y(-event.relative.x * 0.01) camera.rotate_x(-event.relative.y * 0.01) camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-30), deg_to_rad(60)) func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): velocity.y -= gravity * delta # Handle Jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY # Get the input direction and handle the movement/deceleration. # As good practice, you should replace UI actions with custom gameplay actions. var input_dir := Input.get_vector("left", "right", "forward", "back") var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction: velocity.x = direction.x * SPEED velocity.z = direction.z * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED) velocity.z = move_t
@olmrgreen1904
@olmrgreen1904 Год назад
Awesome video!
@felixflache1437
@felixflache1437 Год назад
My up and down camera movement doesn't work. But I have exactly the same code: What can I do?
@NuggetEater-ws7yr
@NuggetEater-ws7yr Год назад
for some reason when i tried to get a character body it didnt show up when i searched it
@MP-pv4eb
@MP-pv4eb Год назад
thanks for this tutorial! I found for me the camera was very twitchy. I'm not sure if there are better solutions for this, but this is what I ended up doing: var x_mov = event.relative.x / 1.7 var y_mov = event.relative.y / 1.7 neck.rotate_y(-x_mov * 0.01) camera.rotate_x(-y_mov * 0.01) you might be able to do it in-line (so, neck.rotate_y((event.relative.x / 1.7) * 0.01) for example), but the variables help my readability. Also, change 1.7 to whatever value is comfortable. Larger value will be slower, "smoother" motion.
@Revenant_Jay09
@Revenant_Jay09 Год назад
How do you fix a null instance?
@zoolanderbestmovie2
@zoolanderbestmovie2 Год назад
cool good job easy to learn continue the hard work
@NarekAvetisyan
@NarekAvetisyan Год назад
Very nice! Can you also make a simple tutorial like this for a Age of Empires style camera?
@hayleypeterson7007
@hayleypeterson7007 5 месяцев назад
This is still such a great tutorial, but I wanted to add that if anyone's gotten a bug when adding camera movement, the fix for me was this line to check MouseMotion was the event type: if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion:
@S.Johannesson
@S.Johannesson 5 месяцев назад
Thank you for this!
@slightlyangrybeluga
@slightlyangrybeluga Год назад
Whenever i try to play it, it crashes, any reason why?
@MidvightMirage
@MidvightMirage 4 месяца назад
how do i change the sensitivity?
@I9096I
@I9096I 9 месяцев назад
How Did You Get The Arrow In Godot?
@badmusicproducer_offical
@badmusicproducer_offical 23 дня назад
HOW DO I MAKE THE CAMERA EVEN LESS FAST?
@bblucat_
@bblucat_ Год назад
Great Video keep it up!
@IMDAGER
@IMDAGER Год назад
I learned so much thank you
@cultofape
@cultofape 2 года назад
Love your tutorials! If I can make a request - 3rd person 3d with LMB click on ground movement and proper player rotation. I just can´t make it 100%right
@BramwellWilliams
@BramwellWilliams 2 года назад
I could do something like that for sure ^^ I've done something like that with gridmaps for tiles you can move to: twitter.com/bramreth/status/1453508866134663174
@grarldbrown6812
@grarldbrown6812 10 месяцев назад
I'm just hoping to use LMB method for camera3D, similar as the way of tutorials does but classic rpg.
@delegalco
@delegalco Год назад
How he get the arrow on the some lines of code ->
@pedrofonseca9062
@pedrofonseca9062 Год назад
How i do the player run???
@hectora.3220
@hectora.3220 4 месяца назад
This is great. Short and usefull.
@eyejar234
@eyejar234 Год назад
Thank you very very much with your help I finaly make 3d first person controller 😃😃😃
@Aneemkhann
@Aneemkhann Год назад
i did what you told me but my character body is not moving nor the camera
@darkBuster2002
@darkBuster2002 Год назад
there is a problem for me Line 17:Assignment is not allowed inside an expression.Line 18:Assignment is not allowed inside an expression.
@foldysnootmack
@foldysnootmack Год назад
I’m having the same issue. Have you figured out how to fix it?
@nezbro2011
@nezbro2011 Год назад
@@foldysnootmack Double equals so type ==
@user-ug6hh4qg3n
@user-ug6hh4qg3n Год назад
@@nezbro2011 Bloody hell really??? DOUBLE EQUALS??? God damn. Good thing I check the comments for answers... Fucking double equals...
@nezbro2011
@nezbro2011 Год назад
@@user-ug6hh4qg3n Yeah not really obvious at first considering there isn't a gap in between the two.
@darkBuster2002
@darkBuster2002 Год назад
@@foldysnootmack No
@Ciac18
@Ciac18 Год назад
thank you so much for this tutorial
@JorgeRosa
@JorgeRosa 2 года назад
Very cool!
@ThaMentalGod2003
@ThaMentalGod2003 Год назад
yo thx for making this godot 4 tutorial 😎
@qcs434
@qcs434 Месяц назад
Brother i have. Big problem My charcter run at out of surface and i want my chacter run at surface plese reply i have a big problem
Далее
How I Fan 3D Cards in Godot 4
9:53
Просмотров 32 тыс.
Копия iPhone с WildBerries
01:00
Просмотров 486 тыс.
У тебя проблемы?
00:20
Просмотров 677 тыс.
choosing a game engine is easy, actually
15:08
Просмотров 351 тыс.
I Melted Wood With Friction
8:44
Просмотров 749 тыс.
Why Do Video Game Studios Avoid Blender?
6:49
Просмотров 424 тыс.
I Paid Fiverr Game Developers to Make the Same Game
10:25
10 Minutes vs. 10 Years of Animation
19:29
Просмотров 698 тыс.
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 491 тыс.
The Strange Graphics Of LETHAL COMPANY
15:59
Просмотров 770 тыс.
Do THIS Before You Publish Your Godot Game
3:33
Просмотров 153 тыс.
I Made the Same Game in 8 Engines
12:34
Просмотров 3,9 млн