PDA

View Full Version : collision detection problems!



psiko_scweek
October 1st, 2006, 06:12
Hey!! whats wrong with my collision detection code? It works great, cept it registers the collision one pixel too many! so, basically it registers one pixel outside of my image.


nt obj_IsCollision(Object *object1, Object *object2)
{
int obj_top1, obj_top2;
int obj_bot1, obj_bot2;
int obj_rigt1, obj_rigt2;
int obj_left1, obj_left2;

obj_left1 = object1->getX();
obj_left2 = object2->getX();

obj_top1 = object1->getY();
obj_top2 = object2->getY();

obj_rigt1 = object1->getX() + object1->getGraphicWidth();
obj_rigt2 = object2->getX() + object2->getGraphicWidth();

obj_bot1 = object1->getY() + object1->getGraphicHeight();
obj_bot2 = object2->getY() + object2->getGraphicHeight();

if (obj_bot1 < obj_top2) return(0);
if (obj_top1 > obj_bot2) return(0);

if (obj_rigt1 < obj_left2) return(0);
if (obj_left1 > obj_rigt2) return(0);

return 1;

yaustar
October 1st, 2006, 13:44
int obj_IsCollision(Object *object1, Object *object2)
{
int obj_top1, obj_top2;
int obj_bot1, obj_bot2;
int obj_rigt1, obj_rigt2;
int obj_left1, obj_left2;

obj_left1 = object1->getX();

obj_left2 = object2->getX();

obj_top1 = object1->getY();

obj_top2 = object2->getY();

obj_rigt1 = object1->getX() + object1->getGraphicWidth();

obj_rigt2 = object2->getX() + object2->getGraphicWidth();

obj_bot1 = object1->getY() + object1->getGraphicHeight();

obj_bot2 = object2->getY() + object2->getGraphicHeight();

if (obj_bot1 <= obj_top2) return(0);

if (obj_top1 >= obj_bot2) return(0);
if (obj_rigt1 <= obj_left2) return(0);

if (obj_left1 >= obj_rigt2) return(0);

return 1;
}.

psiko_scweek
October 1st, 2006, 14:03
lol yeah thats what I have!, i dont know what happened to the code when I copied it, thanks for fixing it.

psiko

psiko_scweek
October 2nd, 2006, 05:14
wow, im retarded, i didnt even see you fixed my problem in that post as well as the issue with my copying.

thanks!