Hi guys, not quite sure on exactly what the problem is with this here… I’ve been scratching my head for days with it.
So, my collision detection works by:
- calculate where an entity wants to be next frame
- do AABB collision detection to check if the entity is allowed to be where it wants to be (by looping over all other entities and nearby tiles)
- if not allowed, work out the maximum the entity can move in the direction it wants to (someone said this a minimum translation vector I think?)
- move as above
It works great. Most of the time. I noticed that occasionally when running the routine above I get a problem like at the end of this gif:
(the white box is the box the collision detection runs on, which is why it is always clipping the other blue boxes)
The minimum movement goes a bit nuts and throws the entity the wrong way to avoid the clipping.
The movement controller class is here: http://pastebin.java-gaming.org/9550b6f511b19.
it has update(delta) method that loops over each entity in the game and checks if it can move (has MoveableEntity interface), wants to move (Entity.state == MOVING), and gets the direction is it going in (MoveableEntity.getFacingDirection). Then it applies collision detection as above.
I am absolutely stuck with this one, I think it only happen when clipping against multiple entities but I haven’t worked out any other conditions. From my code I can’t work out why it can happen - I only check for collisions in the direction the entity is moving in so when moving down it should check for collision below and move up to stop, when moving right it should check the entity to the right and move left to un-collide. In my head I can’t see why this would happen! ARGH!
Any help would be extremely welcomed!