GameMaker Studio 2: Keyboard Movement Tutorial
Вставка
- Опубліковано 8 вер 2024
- We will be looking at the best practices and basic ways to create keyboard movement in GameMaker Studio 2. This is a perfect beginner tutorial for people who want to start making GameMaker Games!
wow this still works thank you
Jesus Christ, I have been trying to do this kind of thing for ages, but everyone made it so god damn complicated. Thank you so much for the simple but very effective video!
ME TO
Use it like this,its better
if(keyboard_check(ord("D"))) x+=6;
if(keyboard_check(ord("A"))) x-=6;
if(keyboard_check(ord("S"))) y+=6;
if(keyboard_check(ord("W"))) y-=6;
Thank you my friend
You also can use: switch(keyboard_key)
Why didn't this work?
Walking_Spead_Halon = 5;
image_speed = 0;
image_index = 2;
if(keyboard_check(ord("A"))){
x -= Walking_Spead_Halon;
image_index = 3;
}
if(keyboard_check(ord("S"))){
y += Walking_Spead_Halon;
image_index = 2;
}
if(keyboard_check(ord("W"))){
y -= Walking_Spead_Halon;
image_index = 0;
}
if(keyboard_check(ord("D"))){
x += Walking_Spead_Halon;
image_index = 1;
}
if(keyboard_check(vk_shift)){
Walking_Spead_Halon = 10;
}
thank you soooooooooooooooo much, i was looking for this like, or 20 minutes already, you are my savior
its easier to use a variable since if you want to change the speed you dont have to go in and change every single 6
I’ve been doing this for like eight hours and it’s literally from five years ago thank you
I just started learning gms2 and I had a feeling I new how to code movement with out any help and I'm glad I was right watching this confirmed I'm actually learning
Awesome good work!
thanks bro your video is perfect
Thank you so much!! This is so basic, I'm still just starting to learn how to program;
stop the ; at the end of your sentence please. its kinda cringey to out coding community. Sorry if I came across as rude, for I am not trying to be
thanks
you just seem like a whiner
fuck off m8;
this is actually much better and neater. In the event type (create) use this code
keyboard_set_map(ord("W"), vk_up);
keyboard_set_map(ord("A"), vk_left);
keyboard_set_map(ord("S"), vk_down);
keyboard_set_map(ord("D"), vk_right);
doesn't work
This video helped me the most. Thank you
That was amazing thank you so much it’s so simple
how could I do it time delayed like when I press the button that makes the player object not directly move forward but charge a number that estimates how far and fast the player object goes into a direction?
How do you make it wasd?
This is pretty great movment system, but can u make video how to set collisions with that system? (Or write it)
I want the WASD keys to control my character, but all the tutorials on youtube do it in code, and i want to do it in drag and drop
plz help :(
its actually really easy. you just make a key press event for each key and assign the move fixed action in the direction you want it to. you also need to do the same thing except with key release, and set the fixed movement speed to 0 so it stops. this makes some buggy movement but if you're looking for a way to use drag and drop, its the way to go.
I can give you some code:)
if (keyboard_check(ord("D"))) {
x += walkspeed;
image_speed = walkspeed/ 3;
sprite_index = SPRITE;
}if (keyboard_check(ord("A"))) {
x -= walkspeed;
image_speed = walkspeed/ 3;
sprite_index = SPRITE;
}if (keyboard_check(ord("S"))) {
y += walkspeed;
image_speed = walkspeed/ 3;
sprite_index = SPRITE;
}if (keyboard_check(ord("W"))) {
y -= walkspeed;
image_speed = walkspeed/ 3;
sprite_index = SPRITE;
}
if(keyboard_check(vk_nokey)) {
image_speed = 0;
image_index = 0;
walkspeed = 3.5;
}
if(keyboard_check(vk_shift)) {
walkspeed = 7;
}
This works nicely but is there a way to control objects with wasd with this code
So the problem with this movement is that if you press both a vertical key and a horizontal key you will be traveling faster than if you only pressed on of the keys.
Let's say speed was set to 5, by pressing up and right the player would be going sq(5) + sq(5) = sq(x), x = sqr(50) = 7.071
The player would be traveling at about 7.071
maybe its a bit late, but there has to be a way to say, set a maximum speed, and make the game check if the actual speed is above the maximum, set the speed back to the maximum
When i press run and it opens, i dont move
it didnt work for me :(
no no no no
No te entendí ni vergas, no sé inglés :c
144p are you serious
just your internet lmao