motion=obj_player.motion; if (place_meeting(x-1,y,obj_player)) move_step(motion,0,obj_block); if (place_meeting(x+1,y,obj_player)) move_step(-motion,0,obj_block); if (place_meeting(x,y+1,obj_player)) move_step(0,-motion,obj_block); if (place_meeting(x,y-1,obj_player)) move_step(0,motion,obj_block);Where "motion" is simply the speed of the player.
Here is also the code for move_step, the piece of code used for my engine:
{
//argument0 - x displacement
//argument1 - y displacement
//argument2 - wall parent
var i,move_check;
for (i = abs(argument0); i > 0; i -= 1)
{
if (i < 0) {i = 0;}
move_check = sign(argument0)*i;
if !(place_meeting(x+move_check,y,argument2))
{
x += move_check;
break;
}
if !(place_meeting(x+move_check,y-i,argument2))
{
y -= i/2;
}
if !(place_meeting(x+move_check,y+i,argument2))
{
y += i/2;
}
}
for (i = abs(argument1); i > 0; i -= 1)
{
if (i < 0) {i = 0;}
move_check = sign(argument1)*i;
if !(place_meeting(x,y+move_check,argument2))
{
y += move_check;
break;
}
if !(place_meeting(x-i,y+move_check,argument2))
{
x -= i/2;
}
if !(place_meeting(x+i,y+move_check,argument2))
{
x += i/2;
}
}
}Using these codes, there is a gap of one pixel between the player and the crate as it moves around. I know that it's because of the collision checking is it checks one pixel behind the desired direction to move. However, I don't know how I could get rid of it. I've tried removing the extra pixel in the collision checking, but then the crate doesn't move. I've also tried using a small mask for the player, but the end result is ugly as the player ends up moving one to two pixels into the walls as well.-Rixeno



Find content
Not Telling
