D
Drago Supremo
Guest
Hi,
i'm working on a simple platform gaming but i'm having some problems handling collisions when i need to change collision masks.
Actually the code to handle collisions looks like this:
-----------------------------------------------------------------------------
//Horizontal collisions
i = 1;
while !(place_meeting(x + i * sign(hsp), y, obj_all_solids)) and (i < hsp * sign(hsp)) i += 1;
i = i * sign(hsp);
if (place_meeting(x + i, y, obj_all_solids)) //Checks for in-range collisions
{
while !(place_meeting(x + sign(hsp), y, obj_all_solids)) x += sign(hsp)
hsp = 0;
}
x += hsp;
//Vertical collisions
i = 1;
while !(place_meeting(x, y + i * sign(vsp), obj_all_solids)) and (i < vsp * sign(vsp)) i += 1;
i = i * sign(vsp);
if (place_meeting(x, y + i, obj_all_solids)) //Checks for in-range collisions
{
while !(place_meeting(x, y + sign(vsp), obj_all_solids)) y += sign(vsp)
vsp = 0;
}
y += vsp;
-------------------------------------------------------------------------
where:
vsp = vertical speed
hsp = horizontal speed
It works fine, but what if i change the collision mask for a smaller one, then i move it without colliding near another object and then in the next frame before the collision checking i change the collision mask to a bigger one for a bigger sprite making it colliding with the object, but not moving? The collision check won't work because at the moment of the check the sprite is already getting stuck into the object.
This is the problem: is there a way to fix it, maybe even completely modifying my collision-checking code?
I can't use the same collision mask for all sprites: they are too different.
I already thought about checking if the sprite is colliding in its position (x, y) and then moving it back until it doesn't collide, but by this way i'm not sure how to make it correctly.
I really hope i explained it sufficiently well and thank you in advance for your help.
i'm working on a simple platform gaming but i'm having some problems handling collisions when i need to change collision masks.
Actually the code to handle collisions looks like this:
-----------------------------------------------------------------------------
//Horizontal collisions
i = 1;
while !(place_meeting(x + i * sign(hsp), y, obj_all_solids)) and (i < hsp * sign(hsp)) i += 1;
i = i * sign(hsp);
if (place_meeting(x + i, y, obj_all_solids)) //Checks for in-range collisions
{
while !(place_meeting(x + sign(hsp), y, obj_all_solids)) x += sign(hsp)
hsp = 0;
}
x += hsp;
//Vertical collisions
i = 1;
while !(place_meeting(x, y + i * sign(vsp), obj_all_solids)) and (i < vsp * sign(vsp)) i += 1;
i = i * sign(vsp);
if (place_meeting(x, y + i, obj_all_solids)) //Checks for in-range collisions
{
while !(place_meeting(x, y + sign(vsp), obj_all_solids)) y += sign(vsp)
vsp = 0;
}
y += vsp;
-------------------------------------------------------------------------
where:
vsp = vertical speed
hsp = horizontal speed
It works fine, but what if i change the collision mask for a smaller one, then i move it without colliding near another object and then in the next frame before the collision checking i change the collision mask to a bigger one for a bigger sprite making it colliding with the object, but not moving? The collision check won't work because at the moment of the check the sprite is already getting stuck into the object.
This is the problem: is there a way to fix it, maybe even completely modifying my collision-checking code?
I can't use the same collision mask for all sprites: they are too different.
I already thought about checking if the sprite is colliding in its position (x, y) and then moving it back until it doesn't collide, but by this way i'm not sure how to make it correctly.
I really hope i explained it sufficiently well and thank you in advance for your help.
Last edited by a moderator: