• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Following tutorial, facing errors.

  • Thread starter UncharteredAnon
  • Start date
U

UncharteredAnon

Guest
Hi guys, day 1 Game Maker 2 owner here and super excited to be taking the plunge... I started looking at some youtube tutorials and found Shaun Spalding's complete platformer tutorial.. AMAZING tutorials provided by him, however i'm getting stuck on one section of a "Horizontal Collision" test and can't seem to move my sprite player at all, the game loads but i can't seem to move him left / right ...

Code i am using

//input from player
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);

//calculate movement
var move = key_right - key_left;
hsp = move * walksp;

//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_Wall))
{
while (!place_meeting(x+sign(hsp),y,Obj_Wall))
{
x = x + sign(hsp);
}

hsp = 0;
}

x = x + hsp;

Just trying to get the feel of things, it's literally the same code/event that was used in Shauns tutorial... am i missing something here?

Any help would be much appreciated!
 
U

UncharteredAnon

Guest
I assume it's something in the "Horizontal Collision" as prior to this step i was able to move left and right freely while going through Obj_Wall
 
Show us a screenshot of how the room is laid out

Also use the </> button on the post editor to bring up a code window when posting code on the forums. It makes it more readable.

Edit: To start with your brackets are all kinds of messed up, try this

GML:
//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_Wall)){


    while (!place_meeting(x+sign(hsp),y,Obj_Wall)){
    x = x + sign(hsp);}

hsp = 0;
}

Every if statement has to have functions inside within {}, and each nested statement the same

GML:
if (question here){
functions peformed if question returns true here

    if (question here){
    statements can also be within other statements like this}
}
of course "if" can be exchanged for else, else if, or while depending on what you're doing

Whether brackets are on their own lines or not is personal preference

GML:
//these are all valid formatting

if (question){
    statements can also be inside other statements like this}




if (question){
    statements can also be inside other statements like this
}




if (question)
{
    statements can also be inside other statements like this
}
 
Last edited:

Nidoking

Member
Have you also included a vertical collision check? Your instance might be overlapping a wall at the bottom of its bounding box and there's just no vertical movement, so it's always been stuck inside a wall and you just didn't check for that before.
 

chamaeleon

Member
I think your issue might be this:
GML:
x = x + hsp;
That would leave your poor player stuck at a fixed location.
Should be this, no?
GML:
x += hsp;
What makes you think this is the case? It isn't, btw, the two are semantically equivalent.
 

hogwater

Member
If your player character doesn't use a single collision mask that never changes, you may be getting stuck because the bounding box changes when your sprite/subimage changes.
 
Top