Loj-Hadron-Collider
Loj-Hadron-Collider copied to clipboard
Question - Using different masks for different interfaces?
Howdy! I've been checking out the LHC and it looks awesome. I am curious, though - does it have any way to use different collision masks for different interfaces? For instance, using one mask for collisions with terrain and a different one for collisions with enemy hitboxes. As far as I can tell by reading the wiki, it seems like this wouldn't be possible if both types of collision are being handled using lhc_add(), since everything's handled within a single lhc_move() call.
Of course, it wouldn't be a big deal if it's necessary to just make a separate obj_hurtbox that sticks to the player and other things with this behaviour, but I figured I'd ask just in case I missed something.
Not in a super clean fashion, I'm afraid. The LHC is designed around a principle of doing as little as is computationally possible to save on search cycles when moving; because of this, it has to use a unified collision mask for all checks (as it uses collision_list functions rather than a separate collision check for every interface). However, you can always swap the collision mask and re-check a collision inside its event. This does, of course, require that the event-specific mask is smaller than or of equal size to the base mask, and adds the overhead of a second check... but only when running that collision event, so it should be pretty efficient compared to other methods regardless.
For example, this is a cleaned up version of what I did in a project where I needed a separate collision mask for solids:
lhc_add("ISolid", function() {
if (mask_index == sPlayerMask1) {
mask_index = sPlayerMask2;
if (!place_meeting(x + (sign(lhc_get_vel_x()) * lhc_collision_horizontal()), y + (sign(lhc_get_vel_y()) * lhc_collision_vertical()), lhc_colliding())) {
mask_index = sPlayerMask1;
return;
}
}
// event code goes here
// ...
mask_index = sPlayerMask1;
});
Ah, I see! Thank you for the very quick and thorough answer, this is super helpful 😁