I am using rigidbody.AddExplosionForce( type impulse) to add an explosion to my boxes. With a cube on the floor with no rotation and an explosion applied on one side, it is propelled in the direction of the explosion. However, I have found that if I turn a box on the Y axis and apply the explosion, it is thrown into the air rather than propelled along the rotated axis.
This it the code on my bomb
using UnityEngine;
using System.Collections;
public class bomb : MonoBehaviour {
// Use this for initialization
public float power = 5.0f;
void Start () {
float range = 2f;
foreach(GameObject block in GameObject.FindGameObjectsWithTag("Player")){
if(Vector3.SqrMagnitude (block.transform.position - transform.position) <= range*range){
block.transform.rigidbody.AddExplosionForce(power, transform.position, range, 0.0f, ForceMode.Impulse);
}
}
}
}
Attached is a demo project. Three boxes, each with a bomb nearby with the above script attached. First box has the bomb at the centre of a face which propels it correctly along the z axis. Second box has the bomb left-of-centre and the box is propelled in the z-axis, whereas it should be heading off to the right. Third box had the box and sphere selected as a group and rotated, so the bomb is in the centre of the face relative to the box’s orientations, but it flies upwards.
Any help greatly appreciated!
1372447–69240–$Test.zip (152 KB)