bitDecayGames / Jump

Tile-based platformer engine aimed at early 90's era platformer capabilities.
MIT License
0 stars 3 forks source link

Dynamic vs Dynamic collisions #120

Open MondayHopscotch opened 8 years ago

MondayHopscotch commented 8 years ago

Have dynamic bodies able to collide with dynamic bodies. One thing we already know is a problem is standing on top of a dynamic body.

UPDATE Pending work on #132

MondayHopscotch commented 8 years ago

I'm foreseeing some major issues trying to implement these types of collisions.

Things we'll need to take into consideration:

MondayHopscotch commented 8 years ago

Other things worth noting:

Currently we only resolve collisions when the body came from past the thing that is pushing it out. This means that We might break things in complex resolution scenarios.

For instance, a player (Dynamic) is standing on top of a crate (Dynamic). The crate is resolving with 2 things, the ground and the player. If the resolution resolves the ground first, then the player, it is likely that the crate is now partially in the ground after resolution has happened.

Next frame, it won't resolve with the ground due to being already inside at the start of next frame.

This means that we might have to collect our resolutions together and resolve any that will push us UP last, to make sure we don't get smashed through things.

For now, I am holding off on this issue because it looks like it will be complex to solve.

MondayHopscotch commented 8 years ago

One thing I thought about that might help this resolve better is to order our resolutions by body type. Process collisions in this order:

Dynamic <-> Dynamic Dynamic <-> Kinetic Dynamic <-> Static

This should make it so that nothing can get resolved through a static body (such as the actual level)

Play with it and see what happens.

MondayHopscotch commented 8 years ago

One more thing to note with dynamic v. dynamic collisions:

The current structure of the engine goes through all dynamic bodies and figures out how to resolve them out of Kinetic and Static bodies. This works because Kinetic and Static bodies can't be moved by others bodies. If any dynamic body is resolved in opposing directions, I have the crush mechanic to make that situation simpler.

Problems are introduced when bodies can push each other around because it means we have to iterate to actually resolve positions. Even the current implementation of crush mechanic has a 1 frame lag between when you'd actually be crushed and when the engine recognizes it.

The more I think on it, the more I think, the more difficulties I see there being.

One options that might work for us is to do a 2-part collisions:

Theoretically, this might allow for collisions to happen, but to not let bodies push each other through the world. Though I bet it would still lead to some buggy interaction.

If we try this route, we will probably have to do the full collision resolution on the dynamic v dynamic so that any parenting can occur before the world corrects things.

MondayHopscotch commented 8 years ago

Use multi step collisions but add special handling depending on what kind of bodies are involved in the collision.

The caveat here is that we will have to only restrictions additional resolutions on axes that the dynamic body has been resolved by static and kinetic bodies against.