Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Player stuck on the side of the screen

A topic by PurpleFade created Sep 05, 2020 Views: 290 Replies: 7
Viewing posts 1 to 5
(4 edits)

My character, which is a blue cube, is stuck on the left side of the screen and won't move when I press the key inputs I coded. Does anybody know a way to fix this? My game engine is Gamemaker Studio 2. I don't want this to put a full stop on my project, as I've been working very hard on it.

Guys, please help. I can't find any solutions to this problem.

Ask in GameMaker forums and discord servers

I like the screenshot, don't forsake. Maybe it's time to comment your code or clean your code if you haven't did it before. It can't be more useful that you could think.

Alright, here's the code I've done so far.

1.

hsp = 0;
vsp = 0;
grv = 0.3;
walksp = 4;

______

2.

//Get Player Input
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;

vsp = vsp = grv;

if (place_meeting(x,y+1,oWall)) && (key_jump)
{
vsp = -7;
}

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

//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

You need to comment your code.Even for yourself

hsp = 0;//horizontal speed
vsp = 0;//vertical speed
grv = 0.3;//gravity
walksp = 4;//walk speed

However, i don't really know this language but why

if (place_meeting(x,y+1,oWall)) && (key_jump)
{ vsp = -7;
}


and not

if (!place_meeting(x,y+1,oWall)) && (key_jump)
{ vsp = -7;
}

Don't even know what that means:     vsp = vsp = grv;  I can't help you more than that, not a language i know. good luck.
Submitted

y + 1 is below the player, because 0,0 is the upper left corner of the screen and  and down are the positives of the y coordenate


Submitted

However...
I think it was

vsp = vsp + grav;

or

vsp += grav;