P.S.: Check out my GML course at 75% off: Udemy. Need some help, or have any suggestions? Comment below, or contact me through Facebook or e-mail: a great day! Keyboard_check(ord(“S”)) checks for S key Keyboard_check(ord(“A”)) checks for A key If you want to use the WASD keys, use the keyboard_check() condition this way: You can try playing with these values to get your intended results. The movement speed I used was 3, the jump speed I used was 13, and the gravity I used was 1. Now you can play the game and jump around with your player. This checks if the player’s vertical position (y) is greater than the room’s height, which implies that it has fallen below the boundaries of the room, and restarts the room.
#GAME MAKER STUDIO 2 PLATFORMER TUTORIAL CODE#
This is fairly simple – just add this code into your Step event: Now let’s make the level restart when the player falls down. Now, your Step event code should look like this: This is to ensure that the player only jumps when it is on the ground and not in midair. So, here we want to see if there is a block under the player. If the condition place_free has to turn true, it will instead turn to false and vice-versa with the keyword not. The second condition is different from the previous one because of the keyword not. So, the player will not be able to jump while holding the up key. On the other hand, keyboard_check remains true until the key is held. The first condition is similar to the previous keyboard_check but only remains true when the key is initially pressed. Now let me explain to you the 2 conditions used. This checks for 2 conditions and if they’re true, sets vertical speed (vspeed) to -13, so that the player will make a jump. If (keyboard_check_pressed(vk_up) and not place_free(x, y + 1)) vspeed = -13 Open your Step event once more and append this code: You’ll see that the player can move around. If you want to, you can try playing your game. Now copy the code above and add it into your Step event.
![game maker studio 2 platformer tutorial game maker studio 2 platformer tutorial](https://thomasgervraud.com/wp-content/uploads/2018/11/cover_image.png)
The x is the horizontal position of the object, and y is its vertical position. So, we’re checking if there is no solid object (here, obj_block) before us before we move.
#GAME MAKER STUDIO 2 PLATFORMER TUTORIAL FREE#
The place_free() function is used to check if the specified place is free from any solid objects. So now that there are two conditions, the hspeed will be changed only if both of them turn out true. What has changed? Yes, there is one more condition, after the and. If (keyboard_check(vk_right) and place_free(x + 3, y)) hspeed = 3 If (keyboard_check(vk_left) and place_free(x – 3, y)) hspeed = -3 So, we’re putting a condition (using “if ()”) and then changing hspeed if the condition turns out true. But if the right key too is not pressed, it just changes hspeed to 0, causing the player to stop. If left key is not pressed, as an alternative it checks for the right key and turns hspeed to 3 so the player moves to the right. It checks if we’ve pressed the left key, then changes hspeed to -3, so the object moves to the left. If on keyboard right key is pressed, set horizontal speed to 3. Hey, if on keyboard left key is pressed, set horizontal speed to -3.
![game maker studio 2 platformer tutorial game maker studio 2 platformer tutorial](https://wagon-wheel.yoyogames.com/sites/5d75794b3c84c70006700381/content_entry5eccf0414d3f9600070c1a47/5ed669e24d3f9600070c1a98/files/tutorial_iso.jpg)
Keyboard_check() is used to check if a key is being pressed on the keyboard, and hspeed is the horizontal movement speed of the object. If you’re not familiar with coding, this might seem a bit confusing. If (keyboard_check(vk_right)) hspeed = 3 If (keyboard_check(vk_left)) hspeed = -3
![game maker studio 2 platformer tutorial game maker studio 2 platformer tutorial](https://opengameart.org/sites/default/files/autotile47_0.png)
Before adding any code in there, take a look at this piece of code. This will stop the player from falling (due to gravity) when it collides with the block object, by turning its vertical speed (vspeed) to 0. So now our player object has gravity and will stick to the ground (as long as it is there).Īdd a collision with obj_block event and add this code: Add an Execute Code action from the control drop-down menu. Open your obj_player and add the Create event. Place the objects in a room and make a level. When you create the obj_block, tick the Solid option. One will be spr_player (for the player) and the other spr_block (which will act as the walls/floor). This is for beginners who want to learn GML. Hey there folks! In this tutorial we’re going to create a simple platformer in GameMaker: Studio, using GML (Game Maker Language).