Object spawned during collision: Object's Y axis to be colliding object's polygon's direction

First off, sorry for the confusing title. Let me explain;

I'm spawning some particle effects and meshes during collision(Dust and rubble pieces used in shootouts). The particle effects have Y=30 as their local velocity. What I want to do is spawn the particle so that it's Y axis is facing the FACE/POLYGON/PLANE of the object it just collided with, so that the particle looks like it's coming off the surface of the polygon that made contact with the bullet. Here's a very simple piece of code that's assigned to my bullet prefab, so gameobject is the bullet itself:

if(hit.gameObject.tag == "environment"){

function OnTriggerEnter( hit : Collider ) { var bli = Instantiate(blistparticle, gameObject.transform.position, hit.gameObject.transform.rotation); var smk = Instantiate(dustparticle, gameObject.transform.position, hit.gameObject.transform.rotation);

Destroy(gameObject); } }

This is a fragment of the actual code as I have different particles spawned for different sort of surfaces that are in the game. I have tried a couple of ways to achieve my goal with no results...


Thanks in advance

You probably won't be able to accomplish it using OnTriggerEnter(), because it doesn't receive collision data.

You'll need to use OnCollisionEnter(collision : Collision), then align the the particle system prefab with the y axis of the normal of the point of contact.

Something like:

function OnCollisionEnter(collision : Collision) {
    var contactPoint = collision.contacts[0];
    var rot = Quaternion.FromToRotation(Vector3.up, contactPoint.normal);
    var pos = contact.point;
    Instantiate(particlePrefab, pos, rot);