playMaker

Author Topic: How do you do explosions?  (Read 8272 times)

Red

  • Hero Member
  • *****
  • Posts: 563
How do you do explosions?
« on: August 28, 2013, 05:39:05 PM »
Reason I'm asking is that the system I've got so far is a bit buggy in that it's not always registering the hits with the damage systems i've built.

Here's how I have it set up so far.

On each enemy there is a trigger volume that is set to detect whenever it collides with an "Area of Effect" tagged object (so, fires, explosions, poison clouds, etc.)

Each "Area of Effect" object has a trigger volume that denotes it's range and area of effect.

Here's where things get interesting... the "trigger event" is firing off even when it's hitting a non Area of Effect item (such as the grenade itself... sure, I could have it do damage if it hits an enemy in just the right spot but that's getting ahead of all this.) I've set it to only trigger with the properly tagged items... and even set up a "is this really tagged properly" action and it's still firing off sometimes (and only when it hits at just the right spot.)

Further, this system is also sometimes not registering the hits at times.

Sure, I know that it's a bit sloppy but I don't know of any other way to do explosions and area of effects without resorting to trigger volumes.

So, how do you do explosions that do damage?

I want to have a defined area where the effect takes effect... so, a poison gas cloud will only affect someone if they wade into it... an explosion will only affect someone if they are within a certain range... that kinda stuff.

I'd like some help here because I'm kinda going out of my head trying to track this thing down.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #1 on: August 28, 2013, 08:18:04 PM »
I've found an example of a function that's within Unity that does this...

http://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html

The "Physics.OverlapSphere" which according to the help files will create an array of all the colliders touching or inside the sphere it's placed on (I would assume that this is stored on the object which is dealing the damage... so, in this case it'd be the explosion prefab I have set up.)

Thing is, it looks to be in need of array functions... Yes, I know that Array maker could probably work with this... but, i'm wondering... how would I do this with Playmaker? Can this be used with Playmaker? being able to use a system that's designed probably for this very specific problem would be far, far better than anything I could possibly hack together.

I'm going to tangent off on a stream-of-consciousness here (kinda) but I was thinking... IF this could be called as an action, then I could call an item in that array by index, I could create a basic for loop in Playmaker by having an int test that detects when it's below 0 as the exit condition... and in the state that accesses the array, I could also do things like a distance check (if i wanted to have damage fall-off... but in my own case for this I'll not do that since I do have other factors in play here.)

So, an easy thing to grab array index N, fill in the damage value and then send the "Hit" event off for that to access it.

This would probably be the best option that I can think of since these explosions have other effects to take into consideration (including a bouncing-betty/cluster-bomb effect.)

« Last Edit: August 28, 2013, 08:27:01 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #2 on: August 28, 2013, 08:42:03 PM »
I was also thinking that a way of handling this could be that if the arrayMaker actions in creating an array stores it in the usual way that Unity does things, then that could mean that if this action was called separately (independantly of ArrayMaker or even Playmaker) and the array is created with a name that the array maker system knows to look for rather than having to use a "find" each time (since that can slow things down.) If I had to store this on a playmaker object, I could have the array itself defined in a separate object that the explosions systems which use the Overlap function...

Again, a bit of a stream-of-consciousness (That's how most of my development starts... me just typing what's coming to my mind.)

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: How do you do explosions?
« Reply #3 on: August 29, 2013, 02:24:03 AM »
Hey Red,

Try this bad boy out (not sure where I found it, most likely Jean made it :D)

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #4 on: August 30, 2013, 08:51:40 AM »
Ooh, I like this! This works nicely!

Though, i'd love to have an optional "get objects within sphere with matching tags" or "only gather rigidbodies" on this one to really amp it up to 11.

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How do you do explosions?
« Reply #5 on: September 09, 2013, 09:58:22 PM »
We can get by layer...
Cheers
Seb

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #6 on: October 28, 2013, 07:06:16 PM »
Sorry for not reading this sooner... You mentioned you're able to get by layer... Is that with this script or with a different one? Don't get me wrong, this script is quite nice but I can't seem to find an option to filter by tag (which would save me quite the heart-ache since I've noticed that this gets mighty slow in the FSM I've got set up when it has to run through all the gibbets that previously killed enemies spawn. And I really don't want to give up on those gibbets because... Gibbets! :D)

What I've got so far does the check... then gets the count of the objects... then one by one goes through the list and tests for tag... if it's the right tag, then it goes through the "apply damage" system... if it's not, it just goes to the next in the list (which is controlled by an int variable.)

P.S. for the sphere check action there is a value called "Amount" and I'm not sure what that means... any ideas? I tried looking at the code and it seems to do with a collider but I'm not sure what that actually means (that and I can't code my way out of a wet-paper-bag so there's that.)
« Last Edit: October 28, 2013, 07:08:19 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #7 on: October 29, 2013, 11:38:41 AM »
So, I've tested (successfully) a way to get through this sluggish-ness of the actions for the explosions that I had up before.

First off, I have two Array list proxies on the explosion prefab. One is called "Sphere" and the other is "Explosion." (don't worry, there's a method to this madness.)

Step one, at the start I have the action that starts off the process take two int variables called "C" and "Total" (where C is "count") and sets them to zero (so as to over-ride any previous data in them that might have been held over from the last time that prefab was used.)

then a "Get position" and a "Sphere check" that uses the location just found and the radius of the sphere is a value that's passed into it from the system that spawned it (since I wanted to give the grenades the option of upgrading the blast radius.) Then I stash that data into the "Sphere" array.

Next action after that one is finished I tell it to get the count of all the objects in the "Sphere" array then when that's finished it goes into the next one which I called "Filter." Oh, and the total number of objects is stored in the "total" int variable.

Now the filter has two transitions... a "Continue" and "Finished." it has at the very top an "int compare" which checks to see if the current count is at or above the total var. if it is, it triggers a "Next" global variable (that's the second phase of this system.) Then it gets with "Array list get" the object at index "c" and stores that in a gameobject variable. Then I compare the tag. if it's either Enemy or Player (because grenades I consider "friendly fire" and all that.) and if it is iether, it transitions to the "Continue." If it is not, it just goes to "Finished"

in the "Continue" transition, I take that game object and add it to the "Explosion" array. Then I add one to the "c" variable and finished brings it back to the "Filter" node. In the "Finished" transition (the one where it's neither player or enemy) it just adds one to the "c" variable and goes back to "filter."

as it goes through this, it will then take all the game objects that are from the "Sphere" array and only bring the enemy or player objects to the "Explosion" array.

Since it iterates through all of that pretty quickly it reaches it's finished point and then will trigger the "Next" global transition (you could just use a regular transition but for me the global transition makes the layout a little more neat and tidy.)

First step in the "Next" node is to reset the "c" var back to 0 with a "Set int." Then it goes through a loop where it will take each object in the "Explosion" array and do the appropriate damage allocation system. Since it doesn't have to cycle through hundreds of objects that won't need to be damaged, this has resulted in it being much faster than before. before it'd take a couple seconds to damage all the enemies if there were a ton of objects in the radius, now it is much faster. Still a little slow but I suspect that's because at this point all those gibbets are spawned and aren't in a pooling system (so there is a noticeable lag... but I hope to change that.)

That said, I haven't given this a test with the NGUI Damage text system I have but that's the next step... and if that's too fast and it trips up I'll have to address that but that's another thread.

Sorry for the wall of text, I hope this helps.
« Last Edit: October 29, 2013, 11:50:28 AM by Red »

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How do you do explosions?
« Reply #8 on: October 29, 2013, 03:57:17 PM »
Hey Red!
Sorry about lose connection with this topic.
You found a great and powerful system.
Amount will be the number of game objects found in that range.
Cheers
Seb

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How do you do explosions?
« Reply #9 on: October 30, 2013, 03:06:33 PM »
Aaah, okay. So, if i wanted to limit the number of objects that the sphere check would take in then I'd place an appropriate value in there...?

If so, well, I can see some positives in that and some areas where some improvement would be idea... the positives would be preventing arrays from getting so overloaded with entries (because I'm sure there's a limit... every variable has em afaik) but the areas of improvement I think would be better served if that action itself could have some additional options to only select objects by either layer or tag (or both.)

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: How do you do explosions?
« Reply #10 on: October 30, 2013, 05:52:12 PM »
Sorry Red.
I think you didn't understand me. Amout is a value than action will give you after the process. So if you get 5 five game object it will return you 5.

About your imporvement ideas: I have the same view. Yes we are geting much unnecessary game objects but the script for that would be very hard and it would be expensive for computer. Unity pro's always say don't use much times GetByTag or GetByLayer. The solution is choise only game object we want inside array.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: How do you do explosions?
« Reply #11 on: October 08, 2017, 07:54:31 AM »
I was googling around for the best way to make area of effect explosion and it brought be back here  ;D

I was reading the while topic, i don't know why should anyone use spherecast and arrays when you can simply create a sphere/circle that will deal ontrigger damage to things caught in the radius and then despawn?

Anyone got a better solution maybe?
Available for Playmaker work