3
\$\begingroup\$

Good day.

To simulate an explosion of a vheicle, I decided to do this:

  • When I need to explode veichle , at runtime, i add rigidibody for every single part of veichle (5-10 part: door, wheel, hood etc), and collider (mesh).
  • I detach them from parent
  • I apply an AddExplosionForce to every single part

This cause a big lag in my game, so I'm supposing this is not the efficent way.

The other way could be to add Rigidbody and Collider in my prefab, with Rigidbody.gravity = false, and isKinematic=true, then enabling after explosion, but also this is not good for performance.

Do you have some suggestions to achive my scope, considering that I could have a lot (5-10) enemy veichles at time on my scene ?

Thanks

\$\endgroup\$
  • \$\begingroup\$ The other way could be to add Rigidbody and Collider in my prefab, with Rigidbody.gravity = false, and isKinematic=true, then enabling after explosion, but also this is not good for performance. The performance may not be too bad if you keep references to rigidbodies \$\endgroup\$ – dnk drone.vs.drones Jul 7 '17 at 9:29
  • 1
    \$\begingroup\$ It's always better to swap some variables (enable gravity, disable kinematic) on already existing components instead of creating X parts/gameobjects in one moment. \$\endgroup\$ – Jacob Jul 7 '17 at 9:36
  • 1
    \$\begingroup\$ Try to create those components on start but disable them. When you want the explosion just re-enable components instead of creating them. You could also make a pool of colliders and rigidbodies and just assign the already created one to your object when needed. \$\endgroup\$ – kolenda Jul 7 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.