Preventing tunneling – setting bodies as bullets

As tunneling through static bodies isn't allowed thanks to continuous collision detection, in some cases we can also enable it on dynamic bodies by setting them as bullets. A bullet performs continuous collision detection with static and dynamic bodies.

Remember, you can experience heavy performance issues if you set all bodies to bullets, so it's up to you to find a compromise between accuracy and performance.

In my experience, I had to set as bullets only some particles and projectiles fired by players or enemies. Normally game characters do not move that fast to require them to be set as bullets.

  1. Change the Main function by adding the highlighted line:
    public function Main() { world=new b2World(new ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.