• 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!

Windows Need help programming Player Controls

A

Aidan Carter

Guest
I am trying to make a player move around freely on the x and y axis (kinda Undertale style for reference) while also not moving through various objects like walls and platforms. I've got the X axis down but when I test the Y movement It doesn't work.
Any help would be greatly appreciated!
Here is the Code:
up = keyboard_check(ord("W"))
left = keyboard_check(ord("A"))
right = keyboard_check(ord("D"))
down = keyboard_check(ord("S"))
xspeed = 0
if(left){
if(place_meeting(x-movespeed,y,Obj_Wall)||place_meeting(x-movespeed,y,Obj_Platform)||place_meeting(x-movespeed,y,Obj_Moving_Platform)){
while(!place_meeting(x-1,y,Obj_Wall)&&!place_meeting(x-1,y,Obj_Platform)&&!place_meeting(x-1,y,Obj_Moving_Platform)){
x = x-1
}
}
else{
x = x - movespeed
}

}

if(right){
if(place_meeting(x+movespeed,y,Obj_Wall)||place_meeting(x+movespeed,y,Obj_Platform)||place_meeting(x+movespeed,y,Obj_Moving_Platform)){
while(!place_meeting(x+1,y,Obj_Wall)&&!place_meeting(x+1,y,Obj_Platform)&&!place_meeting(x+1,y,Obj_Moving_Platform)){
x = x+1
}
}
else{
x = x + movespeed
}

}
//yspeed = yspeed + g
//if(yspeed > 10){
// speed = 10
//}
if(up){
y = y+1
if(place_meeting(x,y+1,Obj_Wall)|| place_meeting(x,y+1,Obj_Platform)||place_meeting(x,y+1,Obj_Moving_Platform)){
while(!place_meeting(x,y+1,Obj_Wall)&& !place_meeting(x,y+1,Obj_Platform)&& !place_meeting(x,y+1,Obj_Moving_Platform)){
y = y + 1
}
yspeed = 0
}
}
if(down){
y = y - 1
if(place_meeting(x,y+yspeed,Obj_Wall)|| place_meeting(x,y+yspeed,Obj_Platform)|| place_meeting(x,y+yspeed,Obj_Moving_Platform)){
while(!place_meeting(x,y-1,Obj_Wall)&& !place_meeting(x,y-1,Obj_Platform)&& !place_meeting(x,y-1,Obj_Moving_Platform)){
y = y - 1
}
yspeed = 0
}
}
vspeed = yspeed
hspeed = xspeed
 

Slyddar

Member
You can also make things simpler by creating a parent object for your solids, say o_solid, and have obj_wall, obj_platform and obj_moving_platform as children. Then you just check for your collision with o_solid only.
 
Top