# GMLObject collision for moving wall

#### zampa

##### Member
So i have a wall in my game that is supposed to move, i set up a collision so that you can not walk through it,
the wall has a path to follow and also it stops if it finds any object in his path.

If i comment/delete in the create event path_start(); the collision works as intended, but if it starts moving there are some issues i can not figure out how to solve:

if the wall moves left or right the top and bottom collision work but the left and right do not, the player gets knocked back or gets slightly stuck in the wall

if the wall moves up and down the left and right collision work but the top and bottom do not, the player gets knocked back or gets slightly stuck in the wall

obj_wall step event: // makes the wall stop
var dir = round(direction/90);
if(dir == 4) dir =0;
switch (dir)
{

case 0:

var r_1 = place_meeting(x+20,y,all);
if(r_1 == 0) path_speed = 2;
else path_speed = 0;
break;

case 1:

var t_1 = place_meeting(x,y-20,all);
if(t_1 == 0) path_speed = 2;
else path_speed = 0;
break;

case 2:

var l_1 = place_meeting(x-20,y,all);
if(l_1 == 0) path_speed = 2;
else path_speed = 0;
break;

case 3:

var b_1 = place_meeting(x,y+20,all);
if(b_1 == 0) path_speed = 2;
else path_speed = 0;
break;

}

obj_player step event: // collision
if(top_collision_o < 0 or image_alpha == 0)
{
var c_o_t_1 = place_meeting(xprevious,y+top_collision_o,obj_wall);
if(c_o_t_1 !=0 ) y = ((bbox_top+32) & ~ 31) - spr_bbox_top;
}
if(bottom_collision_o > 0 or image_alpha == 0)
{
var c_o_b_1 = place_meeting(xprevious,y+bottom_collision_o,obj_wall);
if(c_o_b_1 !=0 ) y = ((bbox_bottom & ~ 31)-1) - spr_bbox_bottom;
}
if(left_collision_o < 0 or image_alpha == 0)
{
var c_o_l_1 = place_meeting(x+left_collision_o,y,obj_wall);
if(c_o_l_1 !=0 ) x = ((bbox_left+32) & ~ 31) - spr_bbox_left;
}
if(right_collision_o > 0 or image_alpha == 0)
{
var c_o_r_1 = place_meeting(x+right_collision_o,y,obj_wall);
if(c_o_r_1 !=0 ) x = ((bbox_right & ~ 31)-1) - spr_bbox_right;
}

This is all the code that could be related to the problem (i think) thanks for the help.

EDIT_1: I have done some debugging, i can control the wall with the arrow keys and i found out that once i move the wall in any direction it creats that problem so, if i move left/right those collision get messed up, and the same goes for moving it up and down with the top and bottom collision

EDIT_2: I also added a command that resets the wall in his original position and if i do that, even after moving it, the collision works

Last edited: