Legacy GM Collision problem?

NoFontNL

Member
If I time my jump right, I get stuck in the block.

My code:
Code:
/// Brick block :: Create Event
image_speed=0;
image_index=0;
jumped=-1;
spinSpeed=0.2
bounceState=0;
reset=-1;

/// Brick block :: Step Event
if (jumped==-1) {
    if ((place_meeting(x,y+1,obj_red) && obj_red.bbox_top > bbox_bottom)) || ((place_meeting(x,y+1,obj_blue)&&obj_blue.bbox_top>bbox_bottom)) {
        jumped=1;
        image_speed=spinSpeed;
        mask_index=mask_none;
        alarm[0] = 4*room_speed;
    }
}
if (jumped==1) {
     scr_block_bounce();
}
if (reset) {
    mask_index=sprite_index;
    if (!collision_rectangle(x-4,y-4,x+4,y+4,obj_red,true,true) && !collision_rectangle(x-4,y-4,x+4,y+4,obj_blue,true,true) ) {
        image_speed=0;
        image_index=0;
        mask_index=sprite_index;
        jumped=-1;
        bounceState=0;
        alarm[0] = -1;
        reset=-1;
    } else {
        mask_index=mask_none;
    }
}

/// Brick block :: alarm[0]
reset = 1;
Further details:
mask_none is an empty sprite with no collision box.
scr_block_bounce() is not important due to it has nothing to do with my collision stuff.
obj_brick is a child of par_ground which is collison checked in obj_blue using Shaun Spalding's collision code.

Note that when I get stuck in one block, when another block is still spinning, the block keeps spinning 'til I get out of the block (as intended, see second gif.)
My intention was to keep the block spinning until I am not colliding with it anymore, but not to get stuck in it.
I used collision_rectangle and place_meeting. Both with the same effect.

Problem: If I time my jump right, I can get stuck in the block. (See first gif)

How can I fix this?

Thanks in advance.
 
Last edited:

Kahrabaa

Member
Code:
if (!collision_rectangle(x-4,y-4,x+4,y+4,obj_red,true,true) && !collision_rectangle(x-4,y-4,x+4,y+4,obj_blue,true,true) ) {
Try changeing the removing the "!" and instead doing like this

Code:
if (collision_rectangle(x-4,y-4,x+4,y+4,obj_red,true,true)=noone && collision_rectangle(x-4,y-4,x+4,y+4,obj_blue,true,true) =noone) {
This might be the reason im not sure. Because "!" checks if the result is 0. collision_rectangle returns an ID or -4. noone representents -4.
 

Kahrabaa

Member
Then it might be that the rectangle that you check collision for is too small, based on the picture where one worked and the other not, it seems that way.

collision_rectangle(x-4,y-4,x+4,y+4,obj_blue,true,true)
This checks 8 pixels large rectangle from the blocks center. The sprite seems larger.

Weird that place meeting didnt work. If that block sprite has precise collisions checked then when the blocks rolls inward it no longer touches the player and resets?
 
Last edited:

NoFontNL

Member
That would have be the problem. Yes, it's fixed now using collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_blue,true,true)
 
Top