Events Continued
Home Up The Platform Problem Events Continued

 

Event handling and the Platform Problem Continued...

So far I've established why it is difficult to put solid-object handling into a collision event. That leaves three obvious candidates:

  1. Step
  2. Just after positions are updated and before collisions
  3. End Step

The step event looks promising. It occurs before collisions so collisions will be evaluated based on where an object finishes up after collisions with walls have been taken into account. The main problems I see are:

Friction, gravity and movement have not been evaluated yet
Collision events that change x and y could put an object into a wall

A step event that occurred between positions being updated and collisions being evaluated would be good. At this point friction and gravity have been taken into account. There is one problem:

There isn't an event at this time

The end step event is a good time to do solid handling. Both the old and new positions of the object are available, in x, y and xprevious, yprevious. If we set the position of the object back to its previous position we can then evaluate a move by its current hspeed and vspeed to ensure that it stops outside solids. Problems:

If a collision event changed hspeed and vspeed the final position will be determined using the changed hspeed, vspeed
If an object stops against a solid object collisions will be evaluated for its projected position not its final position

Solution:

Use the end step event

We will assume that hspeed and vspeed do not change greatly in collision handling. If necessary we can buffer any changes in direction in two variables hs and vs which would be added to hspeed and vspeed at the end of the end step event. The uncertainty in the location of the object when collisions are evaluated will be tolerable most of the time.

Continued...