tag:blogger.com,1999:blog-3729674823895661245.post7307104794497175624..comments2023-07-27T08:33:50.134-07:00Comments on David Waywell: Unity2D: Creating An Explosion EffectThe Spinehttp://www.blogger.com/profile/13306934549725508047noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-3729674823895661245.post-92155416327621321262014-06-19T07:00:41.000-07:002014-06-19T07:00:41.000-07:00Hi there,just wanted to say thanks alot for this v...Hi there,<br>just wanted to say thanks alot for this video. It's exactly what i was looking for. I didnt get it to work in my project, but it i might be on the right track. :)<br><br>Hope that the unity-team includes addexplosionforce2d soon.<br><br>Thanks again, and keep up the good work!Tobias Grahnhttp://media.gobias.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-50920599620402833692014-06-19T07:49:19.000-07:002014-06-19T07:49:19.000-07:00Thanks Tobias. Nice to know someobody found this u...Thanks Tobias. Nice to know someobody found this useful. To be honest, since I did this, I'm been messing with it more and I don't think I'll actually want explosionforce2d now! This method is so customisable.<br><br>And if you need help figuring why it's not working, I'm always here. ;o)<br><br>DavidTheSpinehttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-67611621152862926512014-07-22T14:16:16.000-07:002014-07-22T14:16:16.000-07:00Unless I got something wrong there is a problem wi...Unless I got something wrong there is a problem with this in that you use directional vector with it's unedited size (the further away from the explosion, the longer the vector), resulting in inverted knockback behavior - objects closer to the bomb don't get pushed as much as those further away.<br><br>I can't quite figure out how to edit the values to invert them as to make the explosion have stronger knockback closer to the bomb and cool down with time. Just using inverted value results in strange behavior, where there is very strong knockback close to the center, albeit cooling down very very quickly.Drurynoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-55170410104002487522014-07-22T16:07:01.000-07:002014-07-22T16:07:01.000-07:00Hmmm... Thanks Drury for spotting this. I think yo...Hmmm... Thanks Drury for spotting this. I think you're right. This might be working despite not having that falloff. It's a while since I did this so please forgive me if I get this wrong but I know it worked because I used it in my last game and objects did move slowly the further away from the point of detonation. I think the inverted behaviour (actually makes quite a good sucking mechanism, which I also used) is simply a result of getting the subtraction in the wrong order: bomb - target rather than target - bomb. I never remember which way it's supposed to go. ;)<br><br>Regarding a falloff in force, I think it's probably easy to implement. I'd take the direction vector produced when you subtract the two points (the bomb and the target). Obviously, as you point out, this gets bigger the further way you get from the source but you could get that distance using<br><br>float distance = Mathf.Abs(Vector2.distance(bomb, target));<br><br>Now we have the distance and the direction vector but, as you say, it's the wrong way around but it should be easy to invert it.<br><br>float maximum_bomb_radius = 20f; // the point where the explosive force becomes zero<br>float power = maximum_bomb_radius - distance;<br>if (power < 0)<br>power = 0;<br>Vector2 explosive_force = direction * power; // Here you could also add in any constant to determine the strength of your explosion.<br><br>This is off the top of my head but if you want me to code this, I'll sit down tomorrow and do that.<br><br>Incidentally, there's also an additional parameter to the AddForce method, which I didn't know about at the time but might be helful. If you use AddForce(direction, ForceMode2D.Impuse) you get a force which acts like a sudden brief impulse, as you'd expect from an explosion.<br><br>Hope that helps but feel free to email me if you want me to code it and prove it works.TheSpinehttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-70005949670793903552014-07-23T04:49:36.000-07:002014-07-23T04:49:36.000-07:00Thanks! It works as intended now.You only forgot t...Thanks! It works as intended now.<br><br>You only forgot to use direction.normalized in explosive_force calculation. If you use raw direction, it will take into consideration it's size, and end up somehow nullifying itself with the value of power, causing explosive_force to remain constant at all times (eludes me how exactly, but tests suggest it indeed does).<br><br>So thanks again for the help, this is very useful.Drurynoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-67683496975033129952014-08-22T03:20:37.000-07:002014-08-22T03:20:37.000-07:00I just want to say thanks you for sharing this vid...I just want to say thanks you for sharing this video with us.Pawan Kumarhttp://www.gfxguru.orgnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-69101088613359031292015-03-15T10:23:53.000-07:002015-03-15T10:23:53.000-07:00Can u plz post the code of ur awsm video the explo...Can u plz post the code of ur awsm video the explosion force workaround plz the improved one <br>thnxAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-32140510170795034912015-03-15T15:48:11.000-07:002015-03-15T15:48:11.000-07:00Really sorry. I've checked my work folder and ...Really sorry. I've checked my work folder and that demo I wrote isn't there. I had a hard drive die about twelve months ago so I imagine it was among the many things I lost. There's not that much code and all of it is in the video, if you really need it. Unfortunately, I have work piling up otherwise I'd type it out again for you. :)David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-66107567091399427732015-03-15T18:40:27.000-07:002015-03-15T18:40:27.000-07:00Oh what happnd with mine was that the bomb just di...Oh what happnd with mine was that the bomb just dissapears without doing anything even though i wrote all the target-bomb stuffAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-91705213861174219182015-03-15T18:43:22.000-07:002015-03-15T18:43:22.000-07:00Email me or post your script and I'll take a l...Email me or post your script and I'll take a look in the morning. Sure I can fix it quickly.David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-35662579625663215532015-03-16T06:57:41.000-07:002015-03-16T06:57:41.000-07:00Er did my that source code reach uEr did my that source code reach uAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-81623023672562600712015-03-16T07:00:44.000-07:002015-03-16T07:00:44.000-07:00Not as far as I can see. Send it to thespineblog@g...Not as far as I can see. Send it to thespineblog@gmail.com and I'll keep an eye out for it. I'll have a look as soon as it arrives.<br><br>Incidentally, did you check that you'd correctly selected 'trigger' for the colliders that needed it?David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-28522018180893256972015-03-16T07:06:10.000-07:002015-03-16T07:06:10.000-07:00Only for circle collidr of the bomb ritOnly for circle collidr of the bomb ritAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-67826244875058301002015-03-16T07:11:43.000-07:002015-03-16T07:11:43.000-07:00Okay. Let me just see if I can quickly recreate th...Okay. Let me just see if I can quickly recreate the script... I might be able to do it quickly and send you a working version that way.David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-54393733278307967392015-03-16T07:15:59.000-07:002015-03-16T07:15:59.000-07:00I have sent the mail to ur above specified account...I have sent the mail to ur above specified account <br>thnx in advanceAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-50389060498692851122015-03-16T07:36:25.000-07:002015-03-16T07:36:25.000-07:00Hopefully u got my mailHopefully u got my mailAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-33747351327682605362015-03-16T07:55:40.000-07:002015-03-16T07:55:40.000-07:00Yep. Looking at it now but I have to remember a lo...Yep. Looking at it now but I have to remember a lot of things I've forgotten about Unity. Not used it in a few months...David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-6579476082161617632015-03-16T07:58:56.000-07:002015-03-16T07:58:56.000-07:00Cool by the way i think i found one mistake ie the...Cool by the way i think i found one mistake ie the addforce function isnt it supposed to have x and y componentAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-78368758737652725472015-03-16T08:00:29.000-07:002015-03-16T08:00:29.000-07:00I might hv skipped it i guess but im not able to u...I might hv skipped it i guess but im not able to undrstnd thatAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-22030867580249545512015-03-16T08:01:04.000-07:002015-03-16T08:01:04.000-07:00The vector you created by target-bomb has a direct...The vector you created by target-bomb has a direction. It's correct. I think the problem has something to do with your timings. Not quite figured it out but I think it's exploding too quickly before it affects the other bodies.David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-19855638966474274242015-03-16T08:05:00.000-07:002015-03-16T08:05:00.000-07:00I think ur rit if i give delay as 1 it dissapears ...I think ur rit if i give delay as 1 it dissapears damn fast so i tried givng it Higher value but the green collider thing is explodng smthng lik that not affectng other.bodiesAppunoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-88328862195240471802015-03-16T08:09:39.000-07:002015-03-16T08:09:39.000-07:00I've just sent you an email. I think your scri...I've just sent you an email. I think your script is okay but your timings are probably off. Start small and work up. Start with a 0 sized radius so the explosion starts at a point. Tinker with the value of explosion rate, so it stars small and builds up. You could also change the settings of Time in your project but you probably don't need to do that. FixedUpdate doesn't happen once a frame but *many* times a frame. There's a chance that the explosion could be happening in the space of a single frame. However, I don't think that's the case.<br><br>I quickly created a scene here with a bomb and a few boxes and your script worked once I started the radius at 0.<br><br>Also, make sure that you have 2 colliders on your bomb. One should be a box collider which stops it falling through the floor. The other is the circle collider which has to be a trigger. This is the one we increase so it it passes through objects but triggering their movement.David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-51508844263521330302015-03-22T23:57:24.000-07:002015-03-22T23:57:24.000-07:00hey davidim still getting trouble in that code wel...hey david<br>im still getting trouble in that code <br>well its that the the explosion is not taking place slowly in mine its lik<br>its skipping frames and only final position is being shown.but in ur video it could be made slow. i tried to adjust all the values but still the problem persists.sijonoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-28778308715816165192015-03-23T09:26:00.000-07:002015-03-23T09:26:00.000-07:00I'm really pressed for time today but if you s...I'm really pressed for time today but if you send me the project, I can have a look. It's the only way I'll really be able to figure it out. It could be something really simple like you've played around with your settings for Fixed Update or even some bug with my code. If you send it me, I'll probably get it working.David Waywellhttp://www.the-spine.comnoreply@blogger.comtag:blogger.com,1999:blog-3729674823895661245.post-10614013786999550712015-03-26T22:13:14.000-07:002015-03-26T22:13:14.000-07:00finally figured it out i think the error occured s...finally figured it out <br>i think the error occured since i was using spheres instead of cubes as other objects. sphere also has circle collider in it. when i removed that the explosion is working quite fine. <br>but is there any way i could use circle collider for other objects without getting error?sijonoreply@blogger.com