Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Rigidbody.AddExplosionForce doesn't affect rotational speed

Discussion in 'Physics' started by waltran, Feb 3, 2020.

  1. waltran

    waltran

    Joined:
    Feb 23, 2017
    Posts:
    36
    When i use Rigidbody.AddExplosionForce on my rigidbodies with mesh colliders (meshes and colliders are all convex) the effect is a very nice explosion with parts flying and rotating just as expected.
    but when i remove the colliders, the rigidbodies only gets a force and flies away but with no rotation/torque. so it looks very bland.

    is this the expected behaviour ?
     
  2. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    Sounds correct to me. A rigidbody is described by position, velocity, angular velocity, mass and moment of inertia. The the first three are subject to simulation, the mass can be set in the rigidbodies inspector and moment of inertia is calculated from all child colliders. If you don't have a collider, the moment of inertia tensor would be 0, which would result in an infinite angular velocity for any given non-zero torque.. i guess this is why physx locks rotation on an axis with zero moment of inertia.

    Disclaimer: I didn't take this from the documentation but just from my personal understanding of things.
     
  3. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    464
    Sorry...,
    I actually tried this out and I'm wrong with my assumption, that the moment of inertia would be zero. It actually defaults to (1,1,1), so rotation is not locked. I verified with AddTorque and it works.

    I guess AddExplosionForce does something like looking for the closest point from the explosions origin to the collider and adds force there, which in most cases is a ray the does not intersect with the center of mass, so it also induces torque which makes the object spin.

    Anyhow, the general behaviour makes still sense to me because without a collider, the "closest point" to the explosion origin probably defaults to the center of mass and adding force there doesn't induce torque.

    But.. I was wrong before, so I could be wrong again :)
     
    waltran likes this.
  4. waltran

    waltran

    Joined:
    Feb 23, 2017
    Posts:
    36
    thank you for your response. yeah i think what you said in your second message makes sense.
    Now i use AddForceAtPosition to get even better effect :) at first i thought AddExplosionForce would work similar to AddForceAtPosition but it's not.