The default movement system and collision handling in GM and ENIGMA can be problematic when having multiple moving objects that should never overlap. The reason is that all objects are moved after the step event, and then after they have all been moved, collision handling is done. Since movement and collision checking/handling is interleaved between objects, you may get problematic results where objects end up on top of each other.
One way to bypass these issues is to do the movement and collision checking/handling manually for the moving objects that should never overlap. For instance, you could have your own variables for hspeed, vspeed and gravity (they aren't difficult to simulate, though they may be a bit bothersome), and then in the step event, move the object, check for collisions, and if there are any, simple move back to a position you know is clear (for instance, the previous position). Because you for each object always ensure that they move and check separately, and that they always end up in a clear position, they will never get stuck on each other. You also know that the position at xprevious and yprevious is clear, because the position starts out clear, and there aren't any objects that move between you moving that object and checking for and handling collisions for that object.
The above technique is seen in functions like mp_potential_step, which moves and checks for collisions at the same time.
I wonder if it would be a nice feature to allow the step event and the collision event to be handled together for each object as an option. That wouldn't make much difference in most cases, since interleaving movement and collision checking/handling is not an issue in most games, but in cases where you have multiple moving objects that should not overlap, it could be a lot more convenient than having to simulate hspeed and vspeed and checking for collisions manually.
|