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

GML Moving wall collision

zampa

Member
So i have a moving wall object in my game that follows a path, said walls move other objects along it's path.

I need that if the player collides with let's say the bottom part of the wall (while the wall moves down) to still be able to move normally left and right, and it kinda does it.

See when i launch the game the first time the collision work perfectly:
es: the wall moves to the right i am able to move up and down with no problem
but at the first "turn" the wall makes it doesn't work anymore, even if it moves right again (the direction that previously worked) it kinda stutters, (like it stops for 1-2 frames)

It's highly probable that it has to do with other parts of the code, but could you take a look at the code and see if there is anything wrong that i do not see?

thanks
Code:
var next_x = x+(wall_hspd*wall_move_spd);

var next_y = y+(wall_vspd*wall_move_spd);

if(place_meeting(next_x,next_y,obj_parent_object))
    {
        var n_bbox_right = bbox_right + wall_hspd;

        var n_bbox_left = bbox_left + wall_hspd;

        var n_bbox_top = bbox_top + wall_vspd;

        var n_bbox_bottom = bbox_bottom + wall_vspd;
        
        #region    // move wall close to object
        if(place_meeting(next_x,y,obj_parent_object))
            {
                while(!place_meeting(x+sign(wall_hspd),y,obj_parent_object)) x += wall_hspd;               
            }
            
        if(place_meeting(x,next_y,obj_parent_object))
            {
                while(!place_meeting(x,y+sign(wall_vspd),obj_parent_object)) y += wall_vspd;   
            }
        #endregion
    
        
        

        #region // move objects away from wall
        if(wall_hspd != 0)
            {
                collision_rectangle_list(n_bbox_left,n_bbox_top,n_bbox_right,n_bbox_bottom,obj_parent_object,true,true,lst_wall_collision,false);
                
                var list_len = ds_list_size(lst_wall_collision);
                    
                while(list_len >0)
                    {
                        var check_obj = ds_list_find_value(lst_wall_collision,list_len-1);
                        
                        check_obj.x += wall_hspd*wall_move_spd;
                        
                        list_len--;   
                    }
                    
                ds_list_clear(lst_wall_collision);       
            }
            
        if(wall_vspd != 0)
            {
                collision_rectangle_list(n_bbox_left,n_bbox_top,n_bbox_right,n_bbox_bottom,obj_parent_object,false,true,lst_wall_collision,false);
                
                var list_len = ds_list_size(lst_wall_collision);
                
                while(list_len >0)
                    {
                        var check_obj = ds_list_find_value(lst_wall_collision,list_len-1);
                        
                        check_obj.y += wall_vspd*wall_move_spd;
                        
                        list_len--;   
                    }
                    
                ds_list_clear(lst_wall_collision);       
            }
        #endregion       
    }
 
I think it's this:
Code:
#region    // move wall close to object
       if(place_meeting(next_x,y,obj_parent_object))
           {
               while(!place_meeting(x+sign(wall_hspd),y,obj_parent_object)) x += wall_hspd;               
           }
           
       if(place_meeting(x,next_y,obj_parent_object))
           {
               while(!place_meeting(x,y+sign(wall_vspd),obj_parent_object)) y += wall_vspd;   
           }
       #endregion
Change it to this:
Code:
#region    // move wall close to object
       if(place_meeting(next_x,y,obj_parent_object))
           {
               while(!place_meeting(x+sign(wall_hspd),y,obj_parent_object)) x += sign(wall_hspd);               
           }
           
       if(place_meeting(x,next_y,obj_parent_object))
           {
               while(!place_meeting(x,y+sign(wall_vspd),obj_parent_object)) y += sign(wall_vspd);   
           }
       #endregion
It'd be helpful to have a few screenshots, or at least see the path of the block.
 

zampa

Member
i tred a couple of solutions and wierdly enough if the path takes 90 degrees turns it works there is no stuttering, but i find it kinda limiting am not saying i what it to go is some weird smooth path, but i'd like it to ad least be able to handle 45 degree turns
 
Top