Hi,
I was creating some sort of game and I got a problem with my collision detection technique. Here is how I check the collision:
bool f_CheckCollision(c_Object A, c_Object B)
{
float leftA, leftB;
float rightA, rightB;
float topA, topB;
float bottomA, bottomB;
leftA = A.x;
leftB = B.x;
rightA = A.x + A.w;
rightB = B.x + B.w;
topA = A.y;
topB = B.y;
bottomA = A.y + A.h;
bottomB = B.y + B.h;
//If any of the sides from A are outside of B
if( bottomA <= topB )
{
return false;
}
if( topA >= bottomB )
{
return false;
}
if( rightA <= leftB )
{
return false;
}
if( leftA >= rightB )
{
return false;
}
//If none of the sides from A are outside B
return true;
}
It works ok If my object goes straight on X, or Y but when I press two arrows like UP and DOWN and my object goes trough the wall.
So is there a better way of checking collision between two objects but does not use much of CPU?
Thanks in advance!