I have problems with collision detection in my isometric game - the collision is on a different spot then the actual object is, its like the SDL_Rect is somewhere else then the object itself which is impossible. I checked the values with the debugger it seems there is everything right.
My player has Isometric movement. This is the calculation for the screenworld to isometric
Vector2 Vector2::PosToIso()
{
return Vector2(x - y, (y + x) / 2);
}
When the player doesnt have the isometric movement the collision works fine. I tried to calculate the the objec's x and y pos to iso and i tried with the normal 2D screen values same result.
Collision code:
bool checkCollision( SDL_Rect a, SDL_Rect b )
{
int leftA, leftB;
int rightA, rightB;
int topA, topB;
int bottomA, bottomB;
leftA = a.x;
rightA = a.x + a.w;
topA = a.y;
bottomA = a.y + a.h;
leftB = b.x;
rightB = b.x + b.w;
topB = b.y;
bottomB = b.y + b.h;
if( bottomA < topB )
{
return false;
}
if( topA > bottomB )
{
return false;
}
if( rightA < leftB )
{
return false;
}
if( leftA > rightB )
{
return false;
}
return true;
}