Create an 'Explosion'

Official forum for the Chipmunk2D Physics Library.
Post Reply
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Create an 'Explosion'

Post by lucas »

Hi,
How would you go about creating a shockwave from an explosion?
I was thinking something like this:

Loop through all objects
-if the distance is within a radius
--apply impulse based on distance and angle

Is there a more effecient way to do this? eg. only loop through objects that are within the distance, without the need to check them all

Thanks!
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Create an 'Explosion'

Post by slembcke »

Bounding box and ray traced queries for the spatial hash are high on my list of todo's, but for now there is not a more efficient way of doing it.

Looping over all bodies for doing that probably isn't going to be a performance killer though. Chipmunk already has to iterate over all the bodies several times when integrating anyway. That doesn't even show up on the first page of my profiling chart.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Prio
Posts: 3
Joined: Sat Nov 10, 2007 8:40 pm
Contact:

Re: Create an 'Explosion'

Post by Prio »

Hi,
I was thinking about this before and came up with something(though I haven't actually tried it out).

You could make a body with a circle as a shape. The center of the circle should be the center of your explosion. The radius should be the maxiumum distance of the explosion.

Then set up collision call backs between this explosion shape and things that you want the explosion to move(eg a player). In the callback calculate the distance between the center of the explosion and the object and then apply a suitable force.

If you manage to make this work please let me know ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests