I just started playing around with c++ and some SFML. I'm going to create a 2D game with top view to test my ability and I came across a very big problem: collision detection and physics. So I see at least 4 scenarios:
- An object collides with a solid object (that cannot move) so the first object must stop. (Example: a player hitting a wall)
- An object collides with a movable object (that is not alive so does not move unless pushed) so the first object push that object. (Example: a player that moves a box)
- Two object (that has proper move) moves and collide frontally so they push each other with the same force so they must stay still.
- Two object (that has proper move) and one push the other which is going in the same direction: so the second object must move faster or must have more power. This implies also that if more object push themself one back to the other we have that the first gains a lot of push power. (Example: a crowd that push to to get inside a door and that door with x pushing power gets destroyed)
The collision problem is not a problem at all: you just check the player x and y and width and height against the object that is colliding with. The problem is instead: who is supposed to take care of the collision? Let's say that it's the movable object that is pushing that has to take care of it: (1 scenario), it's ok, the one that pushes just reset its x and y to where it was before colliding; (2 scenario) here things start to get a bit tricky: the pushing object must take care also of the object that gets pushed so it has to move that object too; (3 scenario) here we have two pushing object, which one should deal with the collision? (4 scenario) how do we store the pushing power of the object?
Is there general guidelines for that, considering also that the player is not the only mob and that there might be computer guided mobs?