Search Unity

AddExplosionForce isn't working over network

Discussion in 'Physics' started by ArneSnackaert, Sep 5, 2019.

  1. ArneSnackaert

    ArneSnackaert

    Joined:
    Jun 12, 2019
    Posts:
    7
    Hello,

    I'm currently working on a multiplayer VR game. At the end a major explosion takes place a nuclear reactor explodes. I made a broken reactor and instantiate it at the location of the working reactor. Then I add an explosionForce so that the pieces fly away. He does everything correctly. The good reactor gets destroyed, the fractured one spawns. It checks all objects with a collider and rigidbody. ( I debugged this) and destroys them after 15 seconds. The only thing it doesn't do is add the explosionForce. It does go through the code but they don't fly away. I tried lowering the weight of the rigidbody, changing the explosion force by multiplying it by 10x. It just spawns and doesn't move. They also have a network identity and a network transform set to sync rigidbody 3d.
    This isn't working on serverside, nor client side. (The physics, the spawning works on both sides)
    It just doesn't apply the physics to the children. (all the different pieces under the parent) because if i put a rigidbody on the parent it does move. How do I add a force to the children?

    Working in 2018.4.8f1.

    Here is the simple code:


    Code (CSharp):
    1.  
    2. private void EndExplosion()
    3.     {
    4.         if (!test)
    5.         {
    6.          
    7.             GameObject fracTower = Instantiate(TowerDestruct, intactTower.transform.position, Quaternion.identity) as GameObject;
    8.             NetworkServer.Destroy(intactTower);
    9.             NetworkServer.Spawn(fracTower);
    10.             GameObject explosionFx = Instantiate(explosionEffect, transform) as GameObject;
    11.             NetworkServer.Spawn(explosionFx);
    12.  
    13.             Collider[] colliders = Physics.OverlapSphere(fracTower.transform.position, 150f);
    14.             foreach (Collider hit in colliders)
    15.             {
    16.                 Debug.Log(hit);
    17.                 Rigidbody rb = hit.GetComponent<Rigidbody>();
    18.  
    19.                 if (rb != null)
    20.                 {
    21.                     rb.AddExplosionForce(15000f, fracTower.transform.position, 150f);
    22.                 }
    23.                    Destroy(rb.gameObject, 15f);
    24.             }
    25.             test = true;
    26.         }
    27.     }
     
    Last edited: Sep 5, 2019