D
danel
Guest
I'm new to GMS 2 and watched a couple of tutorials. I've been trying to make a simple platformer ( a red square moving on a line of black squares).
Here's the code i've used for the movement of the player.
As I said in the title, the square only moves when i jump, but when i stand on the ground it stays still.
(grv is set to 0.5 and walksp to 4)
Here's the code i've used for the movement of the player.
Code:
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(ord("W"));
if(place_meeting(x,y+1,oWall))
on_ground=1;
else
on_ground=0;
//left or right
var move = key_right - key_left;
hspeed = move * walksp;
vspeed = vspeed + grv;
if(on_ground && (key_jump))
{
vspeed = -10;
}
//horizontal
if(place_meeting(x+hspeed,y,oWall))
{
while(!place_meeting(x+sign(hspeed),y,oWall))
{
x = x + sign(hspeed);
}
hspeed = 0;
}
x = x + hspeed;
//vertical
if(place_meeting(x,y+vspeed,oWall))
{
while(!place_meeting(x,y+sign(vspeed),oWall))
{
y = y + sign(vspeed);
}
vspeed = 0;
}
y = y + vspeed;
(grv is set to 0.5 and walksp to 4)