So,
I’m implementing collision detection to my 2D game engine and I have some problems as of how to get going.
All my game objects are polygons that I’ve tweeked / implemented myself so the speed is not any problems. However, I wonder how I should detect the collisions…
At the moment I cmp polygon segments with each other i a nice (?) N2 mannor and generate a list of normals that I’ve intersected. The next step is the tricky part though since I don’t know how to react.
I mean, imagine a box approaching a different box horizontally until you detect collision. The collision I’ve detected only contain two normals - the top / bottom surfaces of the testpolygon.
I’ve tried to simply calculate the penetration depth of the collision and seperate the objects from each other according the velocity of the gameobject that collided, but there’s a major bug to that:
What if my gameobject is a person walking on a ground polygon and the person is affected by gravity - Then I detect collisions constantly (to keep the person from falloing though the floor) and when the person tries to move in any direction, he’s more or less stuck!
I feel that I have to calculate scalar-products with the normals of the surfaces that I’ve collided with, but then I have to calculate differently since I havn’t detected the surface directed towards the approaching box in the above example… Gaah!
This is where I hope that you guys come in and make my day a little brighter - Thanx!
/Markus