GameMaker

GameMaker

87 ratings
How to create top down movement!
By Sofy
How to create both basic and advanced top down(up, down, left, right) movement! I noticed that there is no proper guides on how to create code here so as the top gamemaker review holder i thought I'd do it myself :)
4
6
   
Award
Favorite
Favorited
Unfavorite
Welcome!
This is my first guide so sorry if things get a bit confusing!
If you like it feel free to add suggestions for my next guide ♥️

This guide is both assuming your brand new to gamemaker and or just looking for a quick easy to somewhat read guide!

if your new to gamemaker I highly reccomend you type the code rather then copy paste
it helps more then you think
Objects and sprites
For this guide we only need the one object which I'll be calling oPlayer
you might be using objPlayer or obj_player or even o_player! These are all fine!

To create your object, Go to your asset browser (by default should be on the far right of the window)

right click on the objects folder, Hover over create which should expand out a bunch of options. Then find and click object (at time of writing it should be the 5th option).
I'll be naming it oPlayer feel free to do the same!

Sprites
repeat the previous actions but with sprites, Feel free to name it whatever you'd like but I'll be naming mine sPlayerIdle

make sure to import or draw your player sprite and adding it to the player object before continuing
Setting up the room
Warning: This is all for testing purposes do not build your game like this

Create and/or open up room1 within the asset browser!
Now while selecting room1 focus over to the inspecter which is normally located on the far left

Change the room settings to the following (feel free to tinker with these settings if you'd like this is all a learning process!)

Room settings
width = 320 height = 180

Viewport and cameras
enable viewports ✔️

Viewport 0
Visible ✔️ Camera width and height = room settings Viewport width = 1280 Viewport height = 720


Find and drag your player object into the room center

I highly reccomend you watch this video for adding a camera into your game!
Writing some code (create)
Here I'm just going to talk about how to add events! feel free to scroll to the next header-(The code).

Basics
Before we can add some code were going to have to add events! I won't be going into depth about how events work but long story short, its how and when our code runs!

Double click on our player object in our asset browser. A window should open up in your workspace.

In the player object and within the events tab, right click and click add event
Add a Create and Step event.
do not add a begin or end step.

now double click on the create event and lets get started!

The Code
Now for the fun part (atleast for me♥️)
before we start your window should look something like this

First thing we will do is add our movement variables please follow closely and make sure to move to a new line whenever I do!

//whatever text means a comment and affects nothing so you do not have to add if you want.
moveX = 0; moveY = 0; moveSpeed = 1; //change to whatever number you like! (don't use decimals on low res games) currentMoveSpeed = moveSpeed; //Set up input variables inputX = 0; inputY = 0;

and were already done with the create event! :0
Writing some code (step)
Make sure your in the step event window before we begin!

same rules as before!
please follow closely and make sure to move to a new line whenever I do!
//whatever text means a comment and affects nothing so you do not have to add if you want.

Writing code
//Setting the movement input keys right = keyboard_check(ord("D")) left = keyboard_check(ord("A")) up = keyboard_check(ord("W")) down = keyboard_check(ord("S")) //add control to the input //This is a basic equation that sets the correct x/y values for movement inputX = right - left; inputY = down - up; //normalizes the vector ensuring that the player moves at a consistent speed in all directions. var moveLength = sqrt(inputX * inputX + inputY * inputY); if (moveLength > 0) { inputX /= moveLength; inputY /= moveLength; } //get movement moveX = inputX * currentMoveSpeed; moveY = inputY * currentMoveSpeed; //add movement to instance x += moveX; y += moveY; //walking animation if (moveX != 0 or moveY != 0) { sprite_index = walkSprite } else { sprite_index = idleSprite } //optional - mouse direction var _signMouse = sign(mouse_x - x); if (_signMouse != 0) { image_xscale = _signMouse; }
and were already done!! :0
You did it! ♥️
End
Thanks for reading! I hope this helped you in some way or form :)
I'm no teacher but seeing there was no proper guide I knew I had to try!

If you found this helpful please like and leave a rating!
and feel free to ask any questions in the comments or suggest a new guide!


.gif]
37 Comments
Sofy  [author] 12 Aug @ 11:00pm 
yippeeee
d1_god 11 Aug @ 6:28pm 
now i can make my own earthbound type rpg about depression :steamhappy::steamthumbsup:
Шляпичь 8 Jul @ 3:32am 
Вау
Sofy  [author] 30 Jan @ 7:17pm 
yeah sure!!
Dynamic_Creeper 30 Jan @ 12:00pm 
yo, can you make a tutorial for left and right kind of movement? I dunno the term, but stuff like Super Mario Bros games and Cuphead and Hollowknight, stuff like that?
lost my old acc 3 Jan @ 3:21am 
um.. shut the fuck up please???
TricksyPixel 26 Dec, 2024 @ 4:01pm 
░░░░░▐▀█▀▌░░░░▀█▄░░░
░░░░░▐█▄█▌░░░░░░▀█▄░░
░░░░░░▀▄▀░░░▄▄▄▄▄▀▀░░
░░░░▄▄▄██▀▀▀▀░░░░░░░
░░░█▀▄▄▄█░▀▀░░
░░░▌░▄▄▄▐▌▀▀▀░░ THIS IS BOB
▄░▐░░░▄▄░█░▀▀ ░░
▀█▌░░░▄░▀█▀░▀ ░░ COPY AND PASTE HIM,
░░░░░░░▄▄▐▌▄▄░░░ SO HE CAN TAKE
░░░░░░░▀███▀█░▄░░ OVER THE
░░░░░░▐▌▀▄▀▄▀▐▄░░ WORKSHOP (oR eLsE)
░░░░░░▐▀░░░░░░▐▌░░
░░░░░░█░░░░░░░░█░░░
░░░░░▐▌░░░░░░░░░█░░
TricksyPixel 26 Dec, 2024 @ 4:00pm 
░░░░░▐▀█▀▌░░░░▀█▄░░░
░░░░░▐█▄█▌░░░░░░▀█▄░░
░░░░░░▀▄▀░░░▄▄▄▄▄▀▀░░
░░░░▄▄▄██▀▀▀▀░░░░░░░
░░░█▀▄▄▄█░▀▀░░
░░░▌░▄▄▄▐▌▀▀▀░░ THIS IS BOB
▄░▐░░░▄▄░█░▀▀ ░░
▀█▌░░░▄░▀█▀░▀ ░░ COPY AND PASTE HIM,
░░░░░░░▄▄▐▌▄▄░░░ SO HE CAN TAKE
░░░░░░░▀███▀█░▄░░ OVER THE
░░░░░░▐▌▀▄▀▄▀▐▄░░ WORKSHOP
░░░░░░▐▀░░░░░░▐▌░░
░░░░░░█░░░░░░░░█░░░
░░░░░▐▌░░░░░░░░░█░░
Sofy  [author] 27 Nov, 2024 @ 6:07pm 
yay! I'm glad it helped :3
YouEatMopWho 27 Nov, 2024 @ 4:53pm 
Thank you so much for the guide(s)! I really appreciate the explanations because it allowed me to test myself by adding some of my own code, which was only possible because you explained what each chunk was doing. I'm a noob at this so guides like this go a long way, thanks again.