Papa Doge
Member
I'm new to GML (and coding in general) and am having a difficult time figuring out how basic collisions work. I've watched quite a few tutorials now and the code that I'm using seems to be pretty standard.
My issue, is that while my player object does indeed stop where it's supposed to, once the player is butted up against a vertical wall (left or right of the player) I am no longer able to jump up. In fact, all the player is able to do is move in the opposite direction of the wall while on the ground. This presents a problem every time the player wants to jump over a ledge while touching said ledge.
My issue, is that while my player object does indeed stop where it's supposed to, once the player is butted up against a vertical wall (left or right of the player) I am no longer able to jump up. In fact, all the player is able to do is move in the opposite direction of the wall while on the ground. This presents a problem every time the player wants to jump over a ledge while touching said ledge.
Code:
// Collision Checking
// for horizontal movement...
if (place_meeting(x+hsp,y,obj_invisible_wall))
{
// As long as their is NOT a collision within 1 pixel of the direction of movement...
while (!place_meeting(x+sign(hsp),y,obj_invisible_wall))
{
x = x + sign(hsp);
}
hsp = 0;
} else {
// Change the X coordinate to be the object's current position plus horizontal speed.
x = x + hsp;
}
// for vertical movement...
if (place_meeting(x,y+vsp,obj_invisible_wall))
{
// As long as there is NOT a collision within 1 pixel of the direction of movement...
while (!place_meeting(x,y+sign(vsp),obj_invisible_wall))
{
y = y + sign(vsp);
}
vsp = 0;
} else {
// Change the X coordinate to be the object's current position plus vertical speed.
y = y + vsp;
}
Attachments
-
15.5 KB Views: 0