Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Explosion damage/force ideas?

Author
Message
TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 28th Jun 2010 19:48 Edited at: 28th Jun 2010 19:50
I've been wondering this remotely thought as "basic" thing as seen in hundreds of games, grenade explosion physics.

I didn't find any Newton commands specifically for this purpose, so I think this has to be done manually, and I haven't really come up with a great solution.
I was going to make a sphere that expands, then detect any objects hit and use the sphere size value to somehow to apply forces/damage to objects accordingly.
But now I figured out that it would go throught walls etc.

So do you have any ideas how this could be made? I've also though about going to the base mechanics of grenade in real life, and create lots of sharpnel objects that would do the damage and apply the forces of the explosion...

I've to somehow detect objects within the blast radius and apply force to them.
Thebeely
21
Years of Service
User Offline
Joined: 4th May 2005
Location: Croatia
Posted: 28th Jun 2010 20:30
Try using vectors.

create vector from bomb to object
"intersect" it to detect walls

if intersect=0 and vector length<=explosion radius
scale the vector (how hard the explosion will move it)
apply the force vector

And loop that trough your dynamic objects. (Newton, you said)
TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 28th Jun 2010 23:34
I don't know about looping trought every dynamic object, as in my case there could be thousands of entities scattered over huge terrain, but as for now I could try it...
I thought that every Newton body has its own name, but is there sequence of numbers of every object so I could use for-next loop?
Like body 1, 2, 3 ... -> total bodycount.
Thebeely
21
Years of Service
User Offline
Joined: 4th May 2005
Location: Croatia
Posted: 29th Jun 2010 15:41
They don't have names, they have indexes, so yes, you should use for-next loop.

I guess you won't have tens or hundreds of explosions running at all time so thousands of dynamic objects shouldn't be the problem.
Rain Man
18
Years of Service
User Offline
Joined: 19th Nov 2007
Location:
Posted: 30th Jun 2010 08:46
Realistically, hand grenades don't have a lot of explosive force. The explosive is just a propellant for the fragments. You can think of them as being omnidirectional shotgun rounds. All you'd need to do is check for intervening objects (cover) within the area of effect (about 15 meters).

Ten minutes to Wapner.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Jun 2010 12:21
I don't use newton but you might be able to edit my DarkPhysics explosion code to do the job?



Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 30th Jun 2010 19:38 Edited at: 30th Jun 2010 19:38
@baxslash
If you have sparky's collision, you can raycast from where the explosion is to the objects in the blast radius and if there is an object between them, don't effect the object with the explosion.



If it hasn't exploded yet, I haven't touched it.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 30th Jun 2010 19:42
Yes you can but small objects might be missed unless you use a lot of rays but you could also make a sphere the size of the explosion and do a collision check on that...

My version doesn't seem to slow anything down whenever I've used it but both these methods might be slightly faster.

Thanks for the input I'll have a mess around with that later and do some speed comparisons!



Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 30th Jun 2010 19:44
I mean to raycast to check if walls are in the way.

If it hasn't exploded yet, I haven't touched it.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Jun 2010 21:28
Quote: "Yes you can but small objects might be missed unless you use a lot of rays but you could also make a sphere the size of the explosion and do a collision check on that...

My version doesn't seem to slow anything down whenever I've used it but both these methods might be slightly faster.

Thanks for the input I'll have a mess around with that later and do some speed comparisons!
"


no, you cast a ray from the grenade to each object and check if there's an intersection - not a bunch of random rays.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jul 2010 10:39
Oh, sorry I misread but I have to say the collision test using a sphere to look for objects within the blast radius is very efficient.

I'll add in the intersect code too

TuPP3
19
Years of Service
User Offline
Joined: 26th Jan 2007
Location: [+--]FINLAND
Posted: 2nd Jul 2010 00:41 Edited at: 2nd Jul 2010 12:24
I've been messing around with this raycasting idea, the for-next loop throught bodies works fine, I get reaction to every body when the grenade explodes, but I'm missing the key thing, I somehow can't get Newton to return when there is objects intersecting the explosion...

Here is my raycasting, mostly ripped from Newton examples because I'm still learning this, I haven't really done any calculations myself so the exploding force is blowing the objects to the same direction regardless the grenade position.
I should be able to figure those out, but does anyone know why my raycast (for testing I got known certain body number) is returning anything around 0.85 to 0.95 regardless if there is static object(mass 0) intersecting or not.
And when I throw the grenade really far from the object it returns 1.1...

I thought it might be because the grenade and the object are lying on ground, the ray might intersect the floor before reaching the object, but that is not the case because same happens if I throw the grenade in the air and it explodes there with clear line to the object.

Login to post a reply

Server time is: 2026-07-25 08:29:29
Your offset time is: 2026-07-25 08:29:29