Motor Flash Physics: Part 3, frame independent collision detection

This bypasses the limitation of frame-rate dependence. Imagine a situation where a rectangle-shaped movieclip (A) moves towards another rectangle (B). A and B are 10 units wide and their displacement is 10 units. Assuming A’s velocity is 50 units/frame in the x-direction, after 1 frame object A has magically warped through (or tunneled) object B.

So every time the velocities are high, tunneling can occur and collisions would be missed. This is exactly the behavior when using the hitTest() method in flash, which just takes a snapshot every frame and checks the shapes for overlapping.

The new implementation takes this into account and computes the normalized time t{0..1} between two frames. So, if t > 1, a collision may occur in the future (next frame), if the time value falls in the range between 0 and 1, a collision occurred in between two frames and should be handled, and if the value is negative, both objects are already overlapping and must be separated.

There are other techniques such as taking different samples along the projected movement path, but I stick with my implementation because it’ll come in handy when doing collision reactions.

Flash Demo (requires Flash Player 8)

Introducing Chris


I’m Chris and will be helping building the flash physics engine. Hopefully it will improve my coding skills (I wish I had some), and help me use the knowledge I crammed into my head.