Ontrigger activating particles

Lads,

Kinda new to all this…
I have a missile that hits and object. When the object gets hit I’d like it to start emitting smoke particles. I’ve used onTrigger before, but not with particle emitters. Could any of you throw me a small code snippet I could look at?..

Thx,

Stef

OnTriggerEnter is good for “invisible” areas. To hit an object with a missile, usually you add a rigidbody to the missile and use OnCollisionEnter - it supplies additional info that helps instantiating the smoke at the correct point and direction: get the hit point and the surface normal from the first contact point, and rotate the smoke so that it’s emitted perpendicular to the surface. If the target moves, you may have to stick the smoke to it, what can be done by childing the instantiated particle generator to the object:

var smokePrefab: Transform; // drag smoke particles prefab here

function OnCollisionEnter(coll: Collision){
    var contact = coll.contacts[0]; // get the first contact point
    // find the rotation to emit smoke normal to the surface
    var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
    // instantiate the smoke at the hit point
    var smoke = Instantiate(smokePrefab, contact.point, rot);
    // no need to use the line below if the target doesn't move:
    smoke.parent = coll.transform; // "glue" the smoke to the target
}