- Home /
AddExplosionForce doing nothing?
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: http://youtu.be/MiPClBPEgsw
Here's a screen shot of how the Rigidbody components are set:
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;
}
}
Answer by Jeff-Kesselman · Nov 24, 2014 at 09:07 PM
Solved it myself.
It appears it was just putting too much or too little force on the objects. Too much and those effected fly out of frame, to little and they dont move at all.
Your answer
Follow this Question
Related Questions
Add explosion force to button 0 Answers
AddExplosionForce 0 Answers
Instantiated Bomb Not Exploding 1 Answer
How to make helicopter fall and explosion 1 Answer
Rigidbody.AddExplosionForce() Not Playing Nice With Trigger Colliders 1 Answer