### Explosion Physics ??

#### vikingpotato

• Posts: 853
Has anyone been able to get their hands on an explosion physics behavior / system ?

I am talking about something like Fragger grenade or the egg in Angry birds.. The kind of explosion that can inflict damage based on proximity and create directional push on the sorroundings

I am stuck on this, for a project

#### vikingpotato

• Posts: 853
I guess no1 has this working yet..

#### rahulmartin

• Posts: 315
Well i have used some explosions but not of this massive sort, I think youll figure it out , play a while with the physics,

Good luck

#### djip123

• Posts: 987
Hmm, make an actor, make 10 frames in that, spawn a random amount of every frame, would not be that hard stuff
Go check out my website: http://gamecow.net

• Posts: 69
yee the game im currently working on uses something very similar to what djip123 describes; in mine however the closest frames collision has a smaller damage and the damage increases with the farther frames

#### Innes

• Posts: 1961
I haven't put too much though into it, but I think an explosion with appropriate directional force on other objects could be achieved with the following steps:

1) Create a region with its centre at the centre of the explosion. It appears that only rectangular regions can be created at runtime, so perhaps create a circular, off-screen region in the scene designer, and then move it to the appropriate location when the explosion occurs.
2) Use the [For each actor inside region] block to determine which actors are inside the region when the explosion occurs.
3) Calculate the direction of the force based on the centre of the region and the centre of the actor that needs to be pushed. I think this is calculated with atan2(dy, dx).
4) Taking it one step further, the force of the blast could be calculated based on the distance between the centre of the blast and the object to be pushed - increase / decrease the force based on the distance. I think you'd need Pythagorus' Theorum to calculate this.

Apologies if my maths is wrong! If only Maths teachers would use game development to teach trigonometry - I am sure grades would improve dramatically!

I think that problems like this are great learning experiences. If you are still in school, show the code and the game to your teacher for extra credit!
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

#### Tuo

• Posts: 2469
Here is a rather simple explosion coding for the force. Then, all you need to do is add the explosion particle effects. Here's the idea:
1. Set a max distance
2. For every actor (I chose on screen to avoid affecting off-screen enemies) that you want (I used a comparison to see if the actor type was indeed an actor)
3. Set the distance to the distance between the centers (using the Distance Formula from math )
4. If the distance is less than the max, push the actor away from the exploding actor based on how far the actor is (subtracting the distance from the max means that the further actors will feel much less).

(NOTE: I did this in "when created" so it could be used if you had an "explosion" actor that you make when the actor does explode; if you use another system, place it somewhere else )
Don't look to me but rather to the One who is the reason for what I do.

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

#### vikingpotato

• Posts: 853
Polling for each actor on the screen would be costlier than searching inside a region... Also i think it will be visually easier to make levels when the region shows me area of damage through in the editor

#### Tuo

• Posts: 2469
Doesn't mean the idea doesn't work . Just adjust it to your needs!
Don't look to me but rather to the One who is the reason for what I do.

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

#### Innes

• Posts: 1961

Using Tuo's idea, you could loop through each actor of the type of group that can be affected by an explosion, which might be 'cheaper' than looping through every actor.

Give Tuo's idea a try and see how well it performs.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

#### vikingpotato

• Posts: 853
Yes i will. If it works out, i shall put it on forge..