- Home /
Explosion in 2d - scripting practices, speed, multiple explosions
Hi! I am implementing explosion system to my 2d game, I think there should be 2 ways how to approach this
the bomb will execute script that checks which objects are in radius, then calculates the force to apply for each object and apply it. When i did this, only way i found was to iterate through the list of objects, which is very slow, how to do it fast?)
second method is to broadcast event from the bomb, every object then checks if it is in radius, then calculates and apply force on itself, i managed to do this without any problems, but it does not feel like best solution
my question is, what do you think would be best way to do this? I can think of combination of these two, (bomb checks for objects, then attach explode script to them which will destroy itself afterwards)
my concerns are, what happens when 2 bombs explode on same frame close to themselves, and how to do it fast, so overall design simplicity and niceness :)
Include a layermask in your OverlapSphere so you dont end up trying to affect things like the terrain. I believe it makes more sense for the bomb to do the work ins$$anonymous$$d of having multiple objects all perfor$$anonymous$$g checks.
Answer by Greek_Soldier · Mar 13, 2015 at 12:25 PM
What if you made an explosion function and used OverlapCircle with a layermask that filters out bombs and other things that you don't want to effect? Than, you instantiate an explosion prefab at there position before destroying them. The explosion prefab could have a similar script attached to them if you wanted a chain reaction.
Your answer
Follow this Question
Related Questions
Help with orbits 1 Answer
Objects stuck dragging across floor 1 Answer
2D Joint/Wheel Question 1 Answer
CharacterController 2D Move called on inactive controller but it is active... 0 Answers