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

GameMaker Off-screen deactivation disabling object collisions

python-b5

Member
I've been making a Zelda-like top down game in GMS2, where the map is one big room with screen transitions, and I made off-screen objects deactivate themselves so enemies wouldn't move when you can't see them. Normally, when you bump into an enemy you will get hurt, but when I leave the starting screen all the objects stop having collision (place_meeting doesn't work). Does anyone know why this is happening?
 

python-b5

Member
My off-screen deactivation/reactivation code is as follows (in "obj_offscreen"):
Code:
vx = camera_get_view_x(view_camera[0]);
vy = camera_get_view_y(view_camera[0]);

instance_deactivate_object(obj_enemy);
instance_activate_region(vx, vy, 544, 544, true);
And the collision code (in "obj_player"):
Code:
    difference = new_x - x;
    movement_pixel_x = sign(difference);
    x = new_x;
 
    if (tile_danger(x, y) or place_meeting(x, y, obj_enemy)) and hittable and not hit {
        hit = true;
    }
 
    count = 0;
    while tile_collision(x, y) or tile_danger(x, y) or place_meeting(x, y, obj_blockade) or place_meeting(x, y, obj_box) or count > move_speed {
        x -= movement_pixel_x;
        count += 1;
    }

    difference = new_y - y;
    movement_pixel_y = sign(difference);
    y = new_y;
 
    if (tile_danger(x, y) or place_meeting(x, y, obj_enemy)) and hittable and not hit {
        hit = true;
    }
 
    count = 0;
    while tile_collision(x, y) or tile_danger(x, y) or place_meeting(x, y, obj_blockade) or place_meeting(x, y, obj_box) or count > 2 {
        y -= movement_pixel_y;
        count += 1;
    }
 
Last edited:
Top