Is using FixedUpdate() correct in this case?

posted to: Exploding Grenades

According to Debug.Log(), my Explosion() function was getting called twice sometimes, resulting in an explosion with twice the effect. Changing Update() to FixedUpdate() seemed to fix that.

I also added ForceMode.Impulse to AddExplosionForce(), as it's noted in the manual as being good for explosions. I think it looks decent at radius = 5f, power = 10f, liftPower = 10f.

  • Jonathan Gonzalez(jgonzalez) replied

    The issue actually stems from invoking a method in update. Having that in Update means multiple explosions will happen. The reason why it seems to work with FixedUpdate, least in terms of exploding once, is because it has a fixed time of .02 seconds. So that's just enough time to play once before rolling off the platform or getting further from objects. Within Update it happens to explode twice because it's much quicker. It could still play twice with FixedUpdate.

    Ideally this would be called once upon impact. So using something like OnCollisionEnter to start a timer, or just have it explode on contact with an object. 

  • Nicholas Yang(nyanginator) replied

    Thanks for clearing that up!