Legacy GM Object Collision with moving objects

R

RetroKingofHarts

Guest
So, I'm working on a platformer that will use hybrid tile and object collision for floors and walls. I have the tile collision taken care of in another build, so pay no bother to the tiles in this build... as the player doesn't react to those.

My issue is with solid object collision. When the object is perfectly still, the player reacts pixel perfectly the way I want it to... but the issue comes with moving objects. You can spawn moving objects in this build with W,A,S,D... and control with the arrows. You'll see in multiple instances, the player pops all over the place, which he doesn't with stationary objects, and this likely has to do with the collision code not taking into account the moving object moving into the player's bounding box... but I'm not sure how exactly to fix this. My Step event code is as shown below:

Code:
k_l=keyboard_check(vk_left);
k_r=keyboard_check(vk_right);
k_u=keyboard_check(vk_up);
k_d=keyboard_check(vk_down);

// Movement
if (canMove==true)
{
    if (ground==true)
    {
        // Movement based on key control
        var move=k_r-k_l;
       
        // Pressing left
        if (move=-1)
        {
            xsp = -walkSpeed;
        }
        else if (move=1)
        {
            xsp=walkSpeed;
        }
        else xsp=0;
       
        var move2=k_d-k_u;
        // Pressing left
        if (move2=-1)
        {
            ysp=-walkSpeed;
        }
        else if (move2=1)
        {
            ysp=walkSpeed;
        }
        else ysp=0;
    }
}

var obj, dist;
// Floors
dist=max(abs(ysp),1)*sign(ysp);
obj=instance_place(x,y+dist,obj_block);
if (obj) && (y<obj.y)//(ysp>0)
{
    y=obj.bbox_top          -   (sprite_get_height(mask_index) - sprite_get_yoffset(mask_index)) +  (sprite_get_height(mask_index) - sprite_get_bbox_bottom(mask_index)) -1;
    ground=true;
    ysp=0;
}

// Walls
dist=max(abs(xsp),1)*sign(xsp);
obj=instance_place(x+dist,y,obj_block);
if ((obj) && (obj.ptfm_solid==true))
{
    // Right Wall collision
    if (x<obj.x)
    {
        x=obj.bbox_left     -   (sprite_get_width(mask_index) - sprite_get_xoffset(mask_index)) + (sprite_get_width(mask_index) - sprite_get_bbox_right(mask_index))    - 1;
        xsp=0;
    }
    // Left Wall collision
    else
    {
        x=obj.bbox_right    +   sprite_get_xoffset(mask_index)                                  - sprite_get_bbox_left(mask_index)  + 1;
        xsp=0;
    }
}

//Ceiling
dist=max(abs(ysp),1)*sign(ysp);
obj=instance_place(x,y+dist,obj_block);
if (obj) && (y>obj.y)//(ysp<0)
{
    y=obj.bbox_bottom       +   sprite_get_yoffset(mask_index)                                  - sprite_get_bbox_top(mask_index)   + 1;
    ysp=0;
}

// Apply speeds
x+=xsp;
y+=ysp;
PM me for link... the forum isn't letting me post links.
 
Last edited by a moderator:
Top