Realistic bullet explosives?

Hi, I was messing around with ways to do explosives.

I created an IPO-Scale-animation sphere to work as some sort of explosive.
It worked, the objects flew around, but obviously it won’t affect objects that are far away weakly.

I want the explosion to loose effectiveness as it gets larger on objects further away.
IPO-Scale won’t allow this because it is completely solid and will always apply maximum force.

I should be able to recreate the range thing by simply creating multiple spheres, so all I need to do is get spheres to only be a little bit physical.

Is there a way in Bullet to make objects be affected by other objects, but only a little?

The objects colliding with the “collision” sphere get the forces depending on the speed of the hull of the sphere. So you can try to control the speed of the sphere scaling.

You could make the scale IPO of the “explosion”-sphere in a way that it scales up fast first but slows down scale later. The objects colliding with the sphere get the forces depending on the speed of the hull of the sphere.

Example:

frame - scale factor
0 - 0.0
1 - 1.0
2 - 1.5
3 - 1.8
4 - 1.9
etc.

An other way would be to write a python script that adds forces to the objects dependend on the distance to the explosion center.

Using python, you can calculate the distance to an object and use applyImpulse (on the object center) to apply a force. Something like this: (untested code, probably buggy)


g=GameLogic
c=g.getCurrentController()
o=c.owner

maxDist=10 #scale this for the explosion range
maxForce=10 #scale this for force- this is the force applied if the object is at the explosion center, falloff is linear

oblist=g.getCurrentScene().objects
for ob in oblist:
    dist=o.getDistanceTo(ob)
    if dist<maxDist:
        pow=(maxDist-dist)/maxDist*maxPow
        vect=o.getVectTo(ob)[1]
        vect=[vect[0]*pow,vect[1]*pow,vect[2]*pow]
        ob.applyImpulse([0,0,0],vect)

Because this is online I had to use spaces instead of tabs, so you’ll have to add tabs in where I used 5 spaces.

For some extra flare, you can apply extra upward force (it’s more fun when objects go flying upward) and some spin (pull the impulse location toward the center of the explosion a tad) but I’ll leave it to you to figure out how to do that, if you even want to.