Тёмный

How to setup player movement in Godot 4! 

Queble
Подписаться 7 тыс.
Просмотров 74 тыс.
50% 1

In this tutorial, I'll show you how to create a simple yet powerful system for a player movement controller in Godot 4.0!
Most of the examples provided in this video WILL NOT work in pre-4.0 versions of Godot, but you can download the latest build of Godot from the website here: godotengine.org
NOTE: updated video linked in the Pinned Comment! This video is outdated.
Join our discord! : / discord
Join this channel to get access to perks:
/ @queblegamedevelopment...
Need help with Godot?
Book a 1 on 1 tutoring session with me through Fiverr!
www.fiverr.com...
Thanks for watching!
-----------------------------
If you'd like to support my work, you can follow me on Social Media or buy me a coffee! :)
www.buymeacoff...
Instagram: @queble_game_dev
Twitter: @Queble__Games
RU-vid: ... :O
-----------------------------

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

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 112   
@queblegamedevelopment4143
@queblegamedevelopment4143 8 месяцев назад
PLEASE READ: This tutorial is outdated! Instead, please follow this one here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-uNReb-MHsbg.html Thanks! :)
@gavitraxmzproductions9870
@gavitraxmzproductions9870 7 месяцев назад
THANK YOU SO MUCH for going back and adding this. Most people wouldn't and it's really frustrating.
@AlexDiesTrying
@AlexDiesTrying 5 месяцев назад
Spent an hour following it, wondering where all the error messages came from. Maybe the title should say: only works with godot 4.whatever or sth like that. Otherwise I quite liked it. Moving on...
@MagicalAlpaca
@MagicalAlpaca Год назад
Thank you, it’s hard just starting out on godot and trying to learn with 4.0 releases. Every tutorial I try to do is too complicating with the changes. So your videos will help a lot.
@IlluminatiJoeCrusade
@IlluminatiJoeCrusade Год назад
Glad that there's already a tutorial on 4.0. I just downloaded it and was interested in learning game development. You're definitely underrated!
@shakthinandan7124
@shakthinandan7124 Год назад
I did not read anything and straight up jumped into godot 4.0 after not having touched godot for months and was shocked to see kinematic body 2d missing. Boy did I need this 1:57 Hoping to see more vids from you
@theulfhednar2655
@theulfhednar2655 7 месяцев назад
Thx for the help. Used another tutorial as well so now I got both: - Smooth movement - Mouse following rotation This is going well haha
@shardaojha7558
@shardaojha7558 Год назад
Please increase the code font size
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
I'll make sure to do that in the next vid. Thanks for the feedback!
@aneerudh1712
@aneerudh1712 Год назад
Ya wtf 😭 can't see anything
@SleepyP4nda
@SleepyP4nda 8 месяцев назад
Screenshot then zoom
@RealFuzzyYT6
@RealFuzzyYT6 6 месяцев назад
Don’t even need to screenshot u can zoom with RU-vid now
@CookieCrood
@CookieCrood 11 месяцев назад
Wow actually learning something unlike with most of the other tutorial channels and good video quality
@OnBrandRP
@OnBrandRP 10 месяцев назад
THANK YOU! Finally someone that that wrote a non-broken code!
@TheEx404
@TheEx404 Год назад
I really appreciate your time and effort to make this kind tutorial on youtube. Its up to date tutorial and really helpful. Thank you and please teach us more about godot 4.😊😊❤
@paolomontelbano
@paolomontelbano Год назад
Also desperately needed this tutorial, thank you!!!!!
@patolander01
@patolander01 7 месяцев назад
Works perfect in Godot 4.1 just remember to set up the control keys on Project Settings -> Input map . Thanks Queble! !
@muajin
@muajin Год назад
Hi. I'm getting the * Parser Error: Member "velocity" redefined (original in native class 'CharacterBody2D')* error now that i'm using 4.0
@migueltani3549
@migueltani3549 6 месяцев назад
where would you suggest i familiarize myself with this language, i seem to lack enough knowledge to comprehend and understand how the code works, i aim to do so but dont know where to start
@Marandal
@Marandal 4 месяца назад
I Appreciate the movement tutorial. thanks!
@paolomontelbano
@paolomontelbano Год назад
Subscribed just because of your voice, really satisfying lmfao
@chaoraiser2338
@chaoraiser2338 Год назад
so the character can move now but for some reason it doesn't when i start the game is that normal or did i miss something?
@froog3832
@froog3832 Год назад
for me as well. has anyone figured this out?
@marquesguilherme3746
@marquesguilherme3746 Год назад
Thanks for the content, waiting for more godot 4.0 tutorials + 1 sub
@malsypright
@malsypright 9 месяцев назад
Thanks, this was very helpful!
@DrPerky1234
@DrPerky1234 Год назад
Why do you set axis = get_input_axis(). Isn't the variable axis global? Could you leave out the return statement, and simply call get_input_axis() to update axis.
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Yup, I actually just looked this over again today, and saw that XD I'll make an updated more optimized vid soon 👌
@MrAwesomeTheAwesome
@MrAwesomeTheAwesome Год назад
@@queblegamedevelopment4143 Worth noting, this code is broken in Godot 4.1 due to a minor mistake. You have `axis = get_input_axis()`, while setting the value of axis directly in the get_input_axis code. This sets the value of axis to Nil since there is no return value in the function, causing an invalid operand error when running the code. Changing from `axis = ...` to `return ...` the same value that was applied directly solves the issue (and is much cleaner, since this was clearly the intended approach anyways). I was very confused, since I tried to run the exact same thing you had up there, but it was throwing this error. Thought you should know! Otherwise, great tutorial! Subscribed :D
@cv3121
@cv3121 Год назад
How to add jumping to the charcter ?
@imortal1698
@imortal1698 Год назад
bro thats amazing thanks so much
@Xomamaximo
@Xomamaximo Год назад
İm new to godot.And i cant seem to get this to work.When i run the project it cashes when i try to move. it gives an error that says "Invalid operands 'float' and 'vector' in operator '>'." On line 45.I copied the code exactly. And i cant find anything on the internet about this.I dont understand anything from the documentation.Please help.😭
@ladzappy6449
@ladzappy6449 Год назад
I've run into the same error. I've tried 5 different vids and followed every direction, copied each code line for line and still haven't been able to make a character move yet. Lol
@armyofchickens6062
@armyofchickens6062 Год назад
Could you possibly do a tutorial on state machines for top downs?
@AMZTJ
@AMZTJ 10 месяцев назад
this was very helpful, i will be subscribing to you for help like this, thanks!!!
@ThePsychoCap
@ThePsychoCap Год назад
The python scripting changed in Godot 4.0.3stablebuild you can no longer call an assignment inside an expression so now this scripting method no longer works in your configuration in the current build of godot, however your scripting method has opened my eye to vector scripting.
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Oh interesting, thanks for pointing this out! I'll need to re record this one
@ThePsychoCap
@ThePsychoCap Год назад
@@queblegamedevelopment4143 If you find a way to use a vector2 expression somehow in the new build I would appreciate if you could give many any advice.
@FairyOfFlames
@FairyOfFlames 9 месяцев назад
My character is not moving, I'm pretty sure i copied everything correctly and its still not moving. There are also no error warnings. Edit: I deleted some nodes and added the very same. It now works and i have no idea as for why.
@bloop284
@bloop284 Месяц назад
Which ones?
@adannimpa
@adannimpa Год назад
you my friend just help me a lot with this video and you just got a sub from me THANK YOU SO MUCH
@pascalcasier959
@pascalcasier959 Год назад
Nice job, thanks
@vvntic
@vvntic 9 месяцев назад
For the line: axis.x = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left")) is_action_pressed returns a boolean value, does the int turn it into 0 and 1?
@Albert-I
@Albert-I Год назад
I love this tutorial, I understood everything and you explained really great. Although, my character doesn't move and I copied literally everything correct. I don't know what's wrong with my scene. Can someone maybe tell me some common mistakes or something because everything I do, it just doesn't work
@SamRykerTV
@SamRykerTV Год назад
same here. it moves up and left fine, but the right and down are just 1 pixel each press.
@JetMango
@JetMango Год назад
Did you find a solution?
@Albert-I
@Albert-I Год назад
@@JetMango yes, thanks for asking. I just didn't put the script on the player-node. That's why it didn't work. Nice tutorial though!
@kosm460
@kosm460 6 месяцев назад
I hate how they change the syntax every update. I have to search the docs or rewatch tutorials to figure out stuff I already knew. The velocity and move and slide change has kicked my butt
@soran2290
@soran2290 Год назад
Add more zoom
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Noted for future vids! 👍
@pizzagamer2487
@pizzagamer2487 9 месяцев назад
I had so many red zones that I don't understand. I don't know if I messed up or if there was an update that render this useless now. Either way it's a good tutorial.
@ouassimboucetta9179
@ouassimboucetta9179 Год назад
OK but can you Tell me how to move object without any button,just for à rythm game
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
There are many options for achieving this, all of which have different pros and cons depending on the situation obviously. If I understand your question correctly, I'd recommend just putting the movement script inside the _physics_process() function (which executes code every physics frame of the game). Alternatively you could setup the motion inside an animation player or a tween, but this would depend heavily on how you plan on using the motion.
@ouassimboucetta9179
@ouassimboucetta9179 Год назад
@@queblegamedevelopment4143 Thanks 😊
@CarryMe13
@CarryMe13 Год назад
5:21 What is that symbol after "axis". Almost looks like a double equal of something..
@ramonpablito9154
@ramonpablito9154 Год назад
yea press equal two times
@Damglador
@Damglador 7 месяцев назад
Thanks, now my movement doesnt suck
@queblegamedevelopment4143
@queblegamedevelopment4143 7 месяцев назад
Awesome! You should follow my latest player movement video if you want the animations part too!
@PinePlanet
@PinePlanet Год назад
Bro i am getting stuck with collision I even tried motion mode = 1 but the game just keep acting as a platform help me
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Hmm I'm having a hard time understanding exactly what's going on, would you mind describing the problem in more detail? :)
@PinePlanet
@PinePlanet Год назад
@@queblegamedevelopment4143 well I made a top down game by this code extends CharacterBody2D const speed = 100 const friction = 500 const acceleration = 500 @onready var animeplayer = $AnimationPlayer @onready var animetree = $AnimationTree func _ready() -> void: set_motion_mode(MOTION_MODE_FLOATING) func _physics_process(delta): var move_direction = Vector2( Input.get_action_strength("right")- Input.get_action_strength("left"), Input.get_action_strength("down")- Input.get_action_strength("up"), ) move_direction = move_direction.normalized() if (move_direction != Vector2.ZERO): animetree.travel("parameters/moveing/blend_position") velocity = velocity.move_toward(move_direction*speed,acceleration*delta) else : velocity = velocity.move_toward(Vector2.ZERO,friction*delta) move_and_slide() but the player is geting stuck with collision i want it to slide when colliding
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Hmm, I'm not by a computer atm, but I'll see if I can solve it tomorrow 👌
@PinePlanet
@PinePlanet Год назад
@@queblegamedevelopment4143 ok thanks
@santiagodominguezcampillay9737
@santiagodominguezcampillay9737 9 месяцев назад
How can i use state machine within this code? please
@nicnicnic6947
@nicnicnic6947 Год назад
move_and_slide not found in base form any help? I just started with godot yesterday
@Roronoa337
@Roronoa337 Год назад
()
@OnBrandRP
@OnBrandRP 10 месяцев назад
move_and_slide() not move_and_slide
@hb0490
@hb0490 5 месяцев назад
Man I WantedTo Know How To Add Action To Touchscreen Buttons
@suchsneak3545
@suchsneak3545 Год назад
I can't see my comments for some reason, long story short I'm getting an error using vector3 in the move function. Not being able to use ==
@queblegamedevelopment4143
@queblegamedevelopment4143 Год назад
Are you sure you're comparing the input axis to a Vector2? If the input axis is a Vector2 (just x and y values), then it's impossible to compare it to a Vector3 with the == operator
@suchsneak3545
@suchsneak3545 Год назад
@@queblegamedevelopment4143 Oh that makes sense, I'll see if I can fix it
@suchsneak3545
@suchsneak3545 Год назад
@@queblegamedevelopment4143 got it to work somehow lol (I spaced some periods and colons so youtube doesn't delete my comment. func get_input_axis() : var input_dir = Input . get_vector("left", "right", "forward", "back") var axis = (transform . basis * Vector3(input_dir . x, 0, input_dir . y)) . normalized() return axis . normalized()
@sauceboss8693
@sauceboss8693 10 месяцев назад
copied line for line and doesnt work once put into debug mode (character doesnt move at all), collision polygon also doesnt show up in debug.
@sauceboss8693
@sauceboss8693 10 месяцев назад
I didnt make my input names the exact same as they were in the code, so it wasnt calling the movements like it should. make sure inputs are named as they are in the code like move_right
@puypolk
@puypolk 8 месяцев назад
thank you
@Cast-Carnival
@Cast-Carnival 8 месяцев назад
you sound like your name is Adam, and you like to make tiny nerdy things.
@ivava7707
@ivava7707 8 дней назад
Is there a way to have this kind of movement while also having a jump animation ?
@queblegamedevelopment4143
@queblegamedevelopment4143 8 дней назад
Yeah you can do that! Just create a fake z axis variable, and change the jump height with that value. Then you could move the player up by that amount (multiplied by your tile ratio), and also keep the players shadow on the ground
@GoblinBoi666
@GoblinBoi666 3 месяца назад
I think i did everything right but its not working, is this no longer usable?
@queblegamedevelopment4143
@queblegamedevelopment4143 3 месяца назад
If you're on version 4.2, you may want to check out my latest video on this :-)
@GoblinBoi666
@GoblinBoi666 3 месяца назад
​@@queblegamedevelopment4143 I spelled physics wrong 😂
@MayaRuby477
@MayaRuby477 8 месяцев назад
i did everything it said in the video and mine still didn't work, is it cus I'm on the newest version?
@queblegamedevelopment4143
@queblegamedevelopment4143 8 месяцев назад
Hmm, that might be it, but probably not. Are you getting any errors? Also verify that you setup the input map correctly, and if you're still having trouble, try printing out or displaying the velocity to make sure the values are correct. Another thing to note: Since you're multiplying the movement by Delta, you'll want to use higher values, otherwise the motion will be too small to notice. Maybe try adding a 0 to the movement speed if that's the case. Hope this helps!
@MayaRuby477
@MayaRuby477 8 месяцев назад
@@queblegamedevelopment4143 Thank you ill be sure to try these
@MayaRuby477
@MayaRuby477 8 месяцев назад
@@queblegamedevelopment4143 and it didn't show any errors but there are little yellow arrows at the line apply_movement(axis * ACCELERATION * delta) and move(delta)
@TalioUbaldeBaseball-y2z
@TalioUbaldeBaseball-y2z 15 часов назад
whats the background audio for the video
@queblegamedevelopment4143
@queblegamedevelopment4143 15 часов назад
I think I just turned on GameChops radio while I recorded 😅
@itchy_nadz
@itchy_nadz 8 месяцев назад
My character only moves a single pixel at a time. Any ideas?
@itchy_nadz
@itchy_nadz 8 месяцев назад
replaced the code with your pinned comment. Works. My bad
@Zaidoon09
@Zaidoon09 14 дней назад
2:28 How did you save it ? And why?
@queblegamedevelopment4143
@queblegamedevelopment4143 14 дней назад
Control+S to save :) This is so that the scene can be saved in its own file. Once you save a scene, you can create an instance of it anywhere
@Zaidoon09
@Zaidoon09 14 дней назад
@@queblegamedevelopment4143thx❤
@user-hp9tu2fz3f
@user-hp9tu2fz3f 11 месяцев назад
I'm so confused I copied all of it and nothing happened for me 😢
@queblegamedevelopment4143
@queblegamedevelopment4143 11 месяцев назад
Hmmm, is your character a Character body 2d?
@RuditheDinoPerson
@RuditheDinoPerson Месяц назад
For some reason on Line 32 it has an error
@queblegamedevelopment4143
@queblegamedevelopment4143 Месяц назад
What version of Godot are u using? If you're in anything later than 4.0, you should checkout my latest tutorial (pinned comment) on this system :)
@RuditheDinoPerson
@RuditheDinoPerson Месяц назад
@@queblegamedevelopment4143 4.1.2
@josue_gammer
@josue_gammer 7 месяцев назад
I love you men
@MH-lr6ue
@MH-lr6ue 5 месяцев назад
Everyone codes movement differently lol. Just pick a version you like and memorize it
@creammmmmmmmmmmmmmmmm
@creammmmmmmmmmmmmmmmm 3 месяца назад
Please paste the code in the comments
@oxsoverlord9351
@oxsoverlord9351 9 месяцев назад
Does not work as of 12/3/2023
@kingofspades9720
@kingofspades9720 9 месяцев назад
does work as of 12/7/2023, What problem are you having?
@DD-cv1ro
@DD-cv1ro 7 месяцев назад
Code : extends CharacterBody2D #class @export var max_speed = 300 @export var acceleration = 1500 @export var friction = 1200 @onready var axis = Vector2.ZERO func _physics_process(delta): move(delta) func get_input_axis(): axis.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left")) axis.y = int(Input.is_action_pressed("move_down ")) - int(Input.is_action_pressed("move_up")) return axis.normalized() func move (delta): axis = get_input_axis() if axis == Vector2.ZERO: apply_friction(friction * delta) else : apply_movement(axis * acceleration * delta ) move_and_slide() func apply_friction(amount): if velocity.length() > amount: velocity -= velocity.normalized() * amount else : velocity = Vector2.ZERO func apply_movement(accel): velocity += accel velocity = velocity.limit_length(max_speed) # clamp
@fixer3666
@fixer3666 4 месяца назад
thank you, btw you left a space in "move_down"
@sirbananashadow9220
@sirbananashadow9220 10 месяцев назад
I would suggest you do things slower for the guide. I'm trying to follow step by step and i'm getting lost having to slow down the video to see all the actions you take. give the viewer time to follow with you please.
@queblegamedevelopment4143
@queblegamedevelopment4143 10 месяцев назад
Noted :)
@oskarkarlsson4707
@oskarkarlsson4707 6 месяцев назад
skip music please
@queblegamedevelopment4143
@queblegamedevelopment4143 6 месяцев назад
If you wanna checkout my updated video on this topic, it's a bit cleaner and doesn't have music :)
@oskarkarlsson4707
@oskarkarlsson4707 6 месяцев назад
Thank you!
@judgedev2789
@judgedev2789 10 месяцев назад
sh*t Unity is easier lol :D we wrote a lot of codes to move a dumb character :) but in unity you can do this with just 5-6 lines :(
@OnBrandRP
@OnBrandRP 10 месяцев назад
Yeah but Unity can't be trusted.
@kingofspades9720
@kingofspades9720 9 месяцев назад
And you can do this in 2 lines of code if you wanted in godot, He is making it longer to have cleaner code, because its better to have 20 easy to read lines of code than 5 lines of code that you don't remember how they work, and have to look it up or be too afraid to change anything. In Godot you can write func _physics_process(delta): velocity = (((int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left")), int(Input.is_action_pressed("move_down")) - int(Input.is_action_pressed("move_up")).normalized) * delta * 15000).limit_length(300) That is 2 lines of code that does basically the exact same thing, but its just not very readable so you wouldn't do it like that, and honestly, the about 30 lines of code he makes in the video is really nothing, your whole game could easily have 100,000 lines of code in total, and it could be much much more, so I would rather have code that is easy to read if I ever need to change something than code that is a little shorter.
@thenerdydemon1
@thenerdydemon1 9 месяцев назад
It's almost just as many lines in unity but go off ig
Далее
Godot 4.0 | Interaction Tutorial (🤯)
15:43
Просмотров 28 тыс.
I Paid Fiverr Game Developers to Make the Same Game
10:25
I Made My First Game in Godot in 3 Weeks...
26:21
Просмотров 346 тыс.
I Made a Graphics Engine in Scratch
8:27
Просмотров 105 тыс.
I Spent 2,000 Hours Using Scratch
13:59
Просмотров 581 тыс.
The Most Impressive Scratch Projects
11:00
Просмотров 4,9 млн
Can I Remake Super Mario World in Godot? (Part 1)
18:44
I made a game using Godot for the first time
7:35
Просмотров 1,2 млн
6 Years of Learning Game Development
17:20
Просмотров 112 тыс.
I Made the Same Game in 8 Engines
12:34
Просмотров 4 млн
5 tips for better platformer controls
5:22
Просмотров 205 тыс.
How I make my VFX in Godot
9:25
Просмотров 3,6 тыс.