Explosions in Libgdx with Box2d

Block Breaker Gameplay Image Lazer Firing

Sharing is caring!

In a game I’m developing I wanted to have some realistic explosion effects. At first, I thought I would just apply an impulse to all objects within range of the explosion. However, this created unrealistic movement in the affected objects and the objects didn’t rotate. I tried using ray casts to set points to apply the forces to create rotation. This made the explosion look more realistic and worked well enough until the explosions exploded near a static body in which case objects would sometimes be missed as they were shielded by the static body. I decided to dive in fully and use particles to represent the force of the blast.

The first thing I made was an array to store where the explosions would explode and an array to store each particle from the explosion.

Next, I created the method that would be run for each explosion.

I needed to create a class for the Explosion particles which would contain a reference to the body. In this class, I create a body definition and use it to create a Body. The body position is then set to the place the bomb exploded. The linear velocity is then set to give the particle a direction and force. A Fixture is then created to give the body a shape, size, weight etc, and added to the body.

The Box2D world would soon fill up with particles unless they are removed once they’ve finished expelling all their energy.

In my contact listener I have this code to tell the game model to make an explosion

which runs this method in my Game Model

This is how the explosions look when using the box2D debug renderer.

[embedyt] http://www.youtube.com/watch?v=iN6Faut9g0A[/embedyt]

 

Further Reading:

Box2D

LibGDX

Sharing is caring!

13 Replies to “Explosions in Libgdx with Box2d”

  1. Every weekend i used to pay a quick visit this web site, for the reason that
    i want enjoyment, since this this web page conations truly pleasant funny
    data too.

  2. I’ve been exploring for a bit for any high-quality articles oor
    weblog posts on this kind of space . Exploring in Yahoo I at last stumbled upon this
    website. Studying this information So i am happy to express that
    I’ve a very excellent uncanny feeling I discovered
    just what I needed. I such a lot definitely will make sure to don?t
    faill to remember this web site and give it a look regularly.

  3. Every weekend i used to pay a quick visit this web site, for the reason that
    i want enjoyment, since this this web page conations truly pleasant funny
    data too

  4. Saved as a favorite, I love your site!

  5. Magnificent website. Ⅼots of helpful infoгmation here.

  6. Damn, I wiѕh I could think of somеthing smart ⅼike that!

  7. Тhіs іs one օf the Ƅest thingѕ I haѵᥱ rеad thіs mоnth.

  8. ӏs it mʏ computeer оr somebody else too haѕ the
    issue with viewing thiѕ website ᥙnder chrome?

  9. I am sure this paragraph has touched all the internet visitors,
    its really really nice piece of writing on building up new blog.

  10. I don’t realize the way i wound up here, nevertheless i thought this post was good.
    I don’t know your identiity but certainly you happen to be going to a famous blogger if you usually are not
    already 😉 Cheers!

  11. Howdy, I do think your website may be having web browser compatibility problems.
    Whenever I look at your blog in Safari,
    it looks fine however when opening in Internet Explorer, it’s got some overlapping issues.
    I simply wanted to provide you with a quick heads up!
    Aside from that, wonderful site!

  12. this is filled with bots, I just wanna be nice and leave a comment for a future visitor to see. Love from germany.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.