x


How do I make an explosion affect my gameobjects?

I have some Cubes (with rigidbodies) in my scene that I want to blow up. How do I get them to react/get affected by for example a bomb thrown in front of them? I found the following code that works nice, but I would like the cubes to be thrown up in the air as well.

var explosionTime = 1.0;
var explosionRadius = 3.0;
var explosionPower = 500.0;

function executeCollision()
{
    var colliders : Collider[] = Physics.OverlapSphere( transform.position, explosionRadius );  

    for( var hit in colliders )
    {
        if( hit.rigidbody )
            hit.rigidbody.AddExplosionForce( explosionPower, transform.position, explosionRadius );
    }
}
more ▼

asked Jan 26 '11 at 10:45 PM

Mattias Wargren gravatar image

Mattias Wargren
56 17 20 25

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

add this code to your cub (with rigidbody) and it will give them velocity to up every mouse left click. not tested

void Update()
{
if (Input.GetButtonDown("Fire1")) {
rigidbody.velocity = transform.TransformDirection(new Vector3(0, 0, 5f));
}

more ▼

answered Jan 26 '11 at 11:13 PM

mrde gravatar image

mrde
466 7 7 17

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Jan 26 '11 at 11:14 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1866
x1787
x161

asked: Jan 26 '11 at 10:45 PM

Seen: 2154 times

Last Updated: Jan 26 '11 at 11:12 PM