-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExplosion.js
More file actions
41 lines (31 loc) · 964 Bytes
/
Explosion.js
File metadata and controls
41 lines (31 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//explodes an object by replacing it with a destroyed model and flinging it apart
var explosion : GameObject;
var nextpref : GameObject;
var colliders : Collider[];
var expSprite : GameObject;
var radius = 1.0;
var power = 10.0;
function Awake()
{
colliders= Physics.OverlapSphere (transform.position, radius);
}
function OnCarHit()
{
Instantiate(explosion, transform.position, transform.rotation);
Instantiate(nextpref, transform.position, transform.rotation);
Instantiate(expSprite, transform.position, transform.rotation);
Explode();
Destroy (gameObject);
}
function Explode ()
{
// Applies an explosion force to all nearby rigidbodies
var explosionPos : Vector3 = transform.position;
var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
for (var hit : Collider in colliders) {
if (!hit)
continue;
if (hit.rigidbody)
hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 1.0, ForceMode.Impulse);
}
}