- Home /
Spawning explosions and detecting objects in range
Hello!
Here's the deal. I got bombs (note to FBI: virtual ones). When they hit something, the bombs should spawn an immobile explosion that should deal X points of damage to all objects in range.
Now, I currently have a prefab for that explosion object. On that object is a trigger collider, a script, and a few other irrelevant components. In the script I react to OnTriggerEnter(), but that apparently is very unreliable.
I read elsewhere that colliders are quite finnicky, especially when spawned within each other. Might that be my problem? Or maybe there has to be movement in order for collisions to register?
How would you go about applying instant damage to all objects within a collider that was just spawned?
Thanks!
Answer by logty · May 12, 2011 at 03:58 PM
I believe that what you could do is use a spherecast with a radius of your explosion(http://unity3d.com/support/documentation/ScriptReference/Physics.SphereCastAll.html) . Then apply explosion force depending on how far away from the explosion the objects are. Hope this helps!
Hmmm, a sphere cast you say? I like it! Dunno how it's gonna cope with a distance of zero, but I'll try that out. Thanks!
I liked the visual, intuitive setup of the collider though. Also, is there a way to get the layer mask from the project physics settings?
I also liked the Enter and Exit notifications. Bleh, I really wish colliders weren't so broken.
Who says colliders are broken? Where did you "hear" this?