Z
zendraw
Guest
so recently ive wrote a collision code that i find most functional and light then anything ive seen. Collision code that deals with instances and is not grid based, thus giving you maximum freedom of usage.
this is the code
-one thing i need to note, since the distance betwean bbox_left-x and x-bbox_right is never the same, i use (half the calculated width)+1; otherwise the instance gets stuck either on the left or right, top or down.
now the code isnt yet polished and needs work on, but it is basically that, instead of shooting in the dark with a While statement and doing things the hard way, you just calculate the final resault.
the functionality of the code comes mainly from storing the instance that you collide with in a variable. once you have that variable you can do alot.
a more flexible code wuld be this
now you can go crazy with scripts and this can cover all of your collision codes, like interacting with instances. for that you can have a script like this:
and so on. main thing about this is that it doesnt use a grid, it has high funcitonality, and is very light.
this is the code
Code:
var ins=instance_place(x+x_speed, y, o_block);
if (instance_exists(ins))
{
if (ins.block)
{
if (x<ins.x)
{
x=ins.bbox_left-half_mask_width;
} else
{
x=ins.bbox_right+half_mask_width;
}
x_speed=0;
}
}
ins=instance_place(x, y+y_speed, o_block);
if (instance_exists(ins))
{
if (ins.block)
{
if (y<ins.y)
{
y=ins.bbox_top-half_mask_width;
} else
{
y=ins.bbox_bottom+half_mask_width;
}
y_speed=0;
}
}
x+=x_speed;
y+=y_speed;
now the code isnt yet polished and needs work on, but it is basically that, instead of shooting in the dark with a While statement and doing things the hard way, you just calculate the final resault.
the functionality of the code comes mainly from storing the instance that you collide with in a variable. once you have that variable you can do alot.
a more flexible code wuld be this
Code:
var ins=instance_place(x+x_speed, y, o_block);
if (instance_exists(ins))
{
script_execute(scr_collision+ins.type, ins.id, id);
}
ins=instance_place(x, y+y_speed, o_block);
if (instance_exists(ins))
{
script_execute(scr_collision+ins.type, ins.id, id);
}
x+=x_speed;
y+=y_speed;
Code:
switch (argument1.object_index)
{
case o_door:
//interact with door code
break;
case o_portal:
//interact with portal code
break;
}