OnParticleCollision spawning prefab at collision surface normal not working correctly
So I'm spawning blood sprites on the floor/walls using OnParticleCollision. They're spawning on the floor correctly and on walls facing forward/backwards. But on walls facing left/right they spawn sideways.
So as you can see here the normals are being displayed by the debug.drawray and the prefabs are spawning facing the right way. Yet in the screenshot below when next to a left/right facing wall the sprites are instantiated facing the wrong way.
And here's the script which is instantiating the prefabs on collision.
void OnParticleCollision(GameObject other)
{
if (other.layer == 17)
{
int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
int i = 0;
while (i < numCollisionEvents)
{
Vector3 pos = collisionEvents[i].intersection;
Vector3 rotNormal = collisionEvents[i].normal;
Quaternion rot = Quaternion.LookRotation(pos, rotNormal);
Debug.DrawRay(pos, rotNormal, Color.green, 1);
Transform bloodDropClone;
bloodDropClone = Instantiate(bloodDrop, pos, rot);
BloodDrop dropScript;
dropScript = bloodDropClone.GetComponent<BloodDrop>();
dropScript.objToParent = other.transform;
int randomNum;
randomNum = Random.Range(0, 12);
if (randomNum == 3 && playSound)
{
Transform soundClone;
soundClone = Instantiate(bloodSound[Random.Range(0, 2)], pos, other.transform.rotation);
}
i++;
}
}
else
{
//Do nothing
}
}
Answer by imaethan · Sep 28, 2021 at 04:27 PM
Nvm solved it. I was using LookRotation incorrectly.
so now it's
Quaternion rot = Quaternion.LookRotation(rotNormal);
Your answer
Follow this Question
Related Questions
OnParticleCollision() on parent script, for a child particle system? 2 Answers
Using OnparticleCollision noob problem 1 Answer
OnParticleCollision not getting triggered 3 Answers
ParticleCollision Exit Tracking? 0 Answers
Is OnParticleTrigger() can be use on other gameobject the the particleSystem 0 Answers