Hey all, i’m having a small problem with my Instantiate at Particle Collision script. The problem I am facing is figuring out how to instantiate a decal (which already works) with the normal of the collision object (which currently doesn’t work). I have attempted to change the Quaternion.identity to various things that would work in some circumstances, but they all return an error. This leads me to believe I need to do something fancy.

I’ve heard about Collision.contact. Maybe there is something I could do with that.

An example of what I’m trying to do is blood splats that will instantiate on the normal of a collided object, meaning they will face the right way when spawned on walls instead of always facing up.

The meat of the script was found on another answers page and I’ve modified small sections to adjust to my needs.

using UnityEngine;
using System.Collections;

public class ParticleCollisionPrefabInstantiate : MonoBehaviour {

	public GameObject objectToInstantiate;

	private ParticleCollisionEvent[] collisionEvents = new ParticleCollisionEvent[16];

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnParticleCollision(GameObject other /*, Collision collision*/){

		int safeLength = GetComponent<ParticleSystem>().GetSafeCollisionEventSize();
		if (collisionEvents.Length < safeLength)
			collisionEvents = new ParticleCollisionEvent[safeLength];
		int numCollisionEvents = GetComponent<ParticleSystem>().GetCollisionEvents(other, collisionEvents);
		int i = 0;
		while (i < numCollisionEvents) {
			Vector3 collisionHitLoc = collisionEvents*.intersection;*
  •  	Instantiate (objectToInstantiate, collisionHitLoc, Quaternion.identity);* 
    
  •  	i++;*
    
  •  }*
    
  • }*
    }

I worked on it and figured out that all I needed to do was write:

All it does is take the Vector3 normal of a collided object and convert it roughly into a Quaternion.

Much more code is needed to be implemented to wrap to objects or to cut the decal if it doesn’t fit entirely onto the collided object, but it does the job for now.

	Vector3 collisionHitRot = collisionEvents *.normal;*
  • Quaternion HitRot = Quaternion.LookRotation (Vector3.forward, collisionHitRot);*