Original Post
I'm trying to get movement to work in a simple 2d tile game using AABB's To factor in time I do iterative collision checks.. for wall collision, i just check each tile passed over throughout the whole movement. for object->object collision, i break it into steps based on the width/height of the character. It works great for doing character->wall collision and character->character collision alone... but when you collide and hit both character and wall at the same time (the first if statement is true) then it breaks.. acts jumpy and you're able to walk through character and wall... I basically just check for both collision types, and if one had a collision i move to that point... and if both are detected, I move to the closest collision (as that should happen first..).. if no collisions then I just move to my destination... Why does this work fine except in the first if, where both collisions occurred? Does the distance check to determine which to move to not work for some reason? I hope this is something obvious and dumb I'm missing... maybe just need someone else to look at it... thanks
CollDetResult objColl = CollisionDetectionObjects(character, gameTime);
CollDetResult wallColl = CollisionDetectionMap(character, gameTime, map);
if (objColl.DidCollide && wallColl.DidCollide)
{
if (Vector2.Distance(objColl.NewPosition, character.Position)
< Vector2.Distance(wallColl.NewPosition, character.Position))
character.Position = wallColl.NewPosition;
else
character.Position = objColl.NewPosition;
character.StopMoving();
}
else if (objColl.DidCollide)
{
character.Position = objColl.NewPosition;
character.StopMoving();
}
else if (wallColl.DidCollide)
{
character.Position = wallColl.NewPosition;
character.StopMoving();
}
else
{
//both wall and obj should be same here, we can use either
character.Position = wallColl.NewPosition;
character.StopMoving();
}