Okay, Im stumped.
This is a script for a demo, it runs a FPC across a bridge, turns and shoot a lightening bolt at the bridge. The bridge is replaced with a destructible prefab and all the separate parts de-parented from the root so they can travel independently. Finally an explosive force from the
root’s center is applied to all of them to make them fly apart.
BUT they don’t fly apart. they all just drop straight down with gravity together.
Here’s a video of whats happening:
Here’s a screen shot of how the Rigidbody components are set:
[35735-screen+shot+2014-11-24+at+3.08.10+pm.png|35735]
And this is the script. I made adding the explosion happen in the frame after deparenting just in case there was an interaction but it didn’t help
List<Transform> thingsToExplode = new List<Transform>();
Vector3 explosionCenter = new Vector3();
void Update () {
switch (player_state){
case STATE.TURNING:
if (turn<=0){
player_state=STATE.FIRE;
} else {
float turnAmount = Time.deltaTime*turnSpeedPerSec;
turnAmount = Mathf.Min(turnAmount,turn);
turn -= turnAmount;
transform.Rotate(new Vector3(0,turnAmount,0));
}
break;
case STATE.FIRE:
Debug.Log("In FIRE");
bolt.gameObject.transform.LookAt(spelltarget.transform.position);
//SetEmissionRate("lightening_bolt",30);
bolt.gameObject.SetActive(true);
bolt.Play();
player_state=STATE.FIRING;
break;
case STATE.FIRING:
boltTime-= Time.deltaTime;
if (boltTime<=0){
player_state = STATE.HIT;
//SetEmissionRate("lightening_bolt",0);
bolt.Stop();
bolt.Clear();
bolt.gameObject.SetActive(false);
hit.transform.position = spelltarget.transform.position;
//SetEmissionRate("lightening_hit",30);
hit.gameObject.SetActive(true);
}
break;
case STATE.HIT:
hitTime-= Time.deltaTime;
if (hitTime<=0){
player_state = STATE.EXPLODE;
hit.Stop();
hit.Clear();
hit.gameObject.SetActive(false);
GameObject newBridge = (GameObject)Instantiate(replacementPrefab);
Destroy(originalBridge);
explosionCenter = newBridge.transform.position;
// split new bridge up
for(int i=0;i<newBridge.transform.childCount;i++){
Transform child = newBridge.transform.GetChild(i);
child.parent=null;
thingsToExplode.Add(child);
}
}
break;
case STATE.EXPLODE:
Debug.Log("Exploding");
foreach(Transform t in thingsToExplode){
t.rigidbody.AddExplosionForce(5000,explosionCenter,1000);
}
player_state = STATE.DONE;
break;
case STATE.DONE:
break;
}
}