- Home /
(STILL STUCK!) Align Particle Collsion Sub-Emitter (or decal?) with Surface Normal
Okay particle system experts, I really need your help! I've been stuck with this stupid problem for 2 months!! I've learned that decals are probably a better way to go (more efficient?) but I don't know how to instantiate those where the particles hit and in the correct rotation either. I'VE REALLY TRIED HARD BUT I'M REALLY STUCK GUYS!
How can I get a particle sub-emitter to orient itself to match the surface normal of whatever it collides with (terrain and 3D objects)?
I have a blood particle system that looks good, except for one part: the collision sub-emitters. When the blood drops hit a surface, they sub-emit a "splatter" particle. This works well on flat surfaces, but unfortunately when it hits something angled/vertical it doesn't look right and clips. See screenshot for an example of what I'm talking about.
I would like to remove the sub-emitter and use decals instead, if it's not too much trouble for someone to explain how to do that instead?
Will greatly appreciate any help you can provide!!
bump Can anyone out there help me?? I need to figure out how to find the surface normal of a particle collision, then make the particle rotate to match. I can't seem to find the answer out there....
Have you looked at ParticleCollisionEvent and $$anonymous$$onoBehaviour.OnParticleCollision(GameObject)? Looks to me like everything you ask for is right there.
Thanks Cherno, but I'm still stumped. I've re-visited this problem a couple of times during this project, but I still can't figure it out! Can someone please give me a script example? I just want to make the blood splats align to the surfaces they hit. Currently the splatters are sub-particles, but they could be decals ins$$anonymous$$d? Surely someone out there can help me out!
Take my advice and forget about it. I've been trying to find a solution for the same thing for months and haven't found ANY information whatsoever or got any help from the forums. All I get for answer is a link to some decal asset that only works in editor and not during gameplay. It's frustrating as hell to see something basic like a decal to be so complicated when games since Doom 1 had it.
Answer by wightwhale · Mar 17, 2016 at 02:18 AM
private void MoveParticlesOnTerrain(ParticleSystem ps)
{
int numParticlesAlive = ps.GetParticles(m_Particles);
if (m_Particles == null || m_Particles.Length < ps.maxParticles)
m_Particles = new ParticleSystem.Particle[ps.maxParticles];
// Change only the particles that are alive
for (int i = 0; i < numParticlesAlive; i++)
{
RaycastHit raycastHit;
Ray r = new Ray(m_Particles[i].position + Vector3.up * 100f, Vector3.up * -1f);
if (Physics.Raycast(r, out raycastHit, terrainLayer))
{
Quaternion rot = Quaternion.FromToRotation(Vector3.forward, raycastHit.normal);
m_Particles[i].axisOfRotation = Vector3.forward;
m_Particles[i].rotation3D = rot.eulerAngles;
m_Particles[i].position = new Vector3(m_Particles[i].position.x,
gravity.currentTerrain.SampleHeight(m_Particles[i].position) + .1f,
m_Particles[i].position.z);
}
}
ps.SetParticles(m_Particles, numParticlesAlive);
}
private void MoveParticleSystemOnTerrain(ParticleSystem ps)
{
ps.transform.position = new Vector3(ps.transform.position.x,
gravity.currentTerrain.SampleHeight(ps.transform.position) + .1f,
ps.transform.position.z);
}
Thanks man! I actually did end up finally building a solution. It looks similar to this, so I'm assu$$anonymous$$g it will work.
Sorry to anyone else who came across this post and was stumped. I should have posted my code up here when I figured it out. Forgot all about it.
Your answer
Follow this Question
Related Questions
Particle System's Normal Direction makes the former invisible at a certain angle. 1 Answer
Matching collision normal for sub-emitter 0 Answers
Particle System - trailing blood 2 Answers
How can I create a particle 'vortex' or implosion using Shuriken? 2 Answers
Can I slow down a Particle System? - e.g. Slow Motion Effect 1 Answer