- Home /
How to keep particles moving past an obstacle after they have collided with it?
I have this simple setup: a particle system firing at an obstacle with a collider. The particle system has Collision enabled, type is World, Bounce at 0. The scene looks like this:
As you can see, the particles slide along the surface of the obstacle after the collision. What I'm trying to do is making the particles fly past the obstacle after they have slided off its surface. In other words, make the particle system behaves like air flow of some kind of gas or smoke. I think this image sort of illustrates my intended effect: How do I do this in Unity?
Answer by cailem02 · Oct 10, 2018 at 03:49 PM
Turn the collider component off hope this helped (I'm a noob sorry)
Unfortunately, this is not what I wanted. I don't want the particles to move through the obstacle. To others reading this comment: I want to make it very clear that cailem02's reply did not resolve my issue.
Answer by richardkettlewell · Oct 13, 2018 at 05:57 PM
Use the velocity over lifetime module to set a constant velocity in the direction you want.
The velocity over lifetime module does not continue applying the particles' velocities after they collide. It seems that whatever constant velocity it applied to the particles was overridden by the collision module at the point the collision module calculates bounce (which in this case, Bounce = 0). So unfortunately, this is not the solution.
you're right. I just tried it and it doesn't work, because the collision module negates the effect of the velocity module.
in addition to my previous suggestion, i think you could try adding a script to set the particle velocity to 0 via script each frame. i.e.(ps.GetParticles(particles), particles[i].velocity = Vector3.zero; ps.SetParticles(particles)). but if that doesn't work, i'm out of ideas...
Answer by AlterHaudegen · Mar 08, 2020 at 04:57 PM
While searching for the same problem I came upon this post, in case anybody is doing the same: You can nowadays achieve the desired effect with Particle Force Fields.
I will not mark this as Accepted, unfortunately. Read further for a detailed reasoning.
In order to achieve something resembling the actual effect in my original post - i.e keeping particles moving past an obstacle after sliding off its surface - you have to supply a Texture3D that describes the flow of the particles in the Volume Texture field so that when particles move through the field, they slide along the surface of the obstacle before being pulled past the obstacle's surface, not immediately pulled toward the start range, not immediately repelled out of the end range.
This feature only supports 4 primitive shapes: Sphere, Hemisphere, Cylinder and Box. You cannot take the shape of a mesh directly or indirectly as the shape of the Particle System Force Field. The example of air flow sliding across the surface of a car mesh as seen in the original post is still not achieved with this method.
Particle System Force Field is ultimately meant to represent a field in empty space that either gravitates or repels particles. It is not meant to represent a solid object that particles in real life can slide past along its surface.
It should work in combination with the collision module of the particle system. I’ll try some experiments to be sure.
I know this (adding in a mesh collider) won't work because I have thought of it ahead of time and tried it myself. The inevitable thing that's going to happen as soon as particles collide with a collider is bounce is calculated and any existing velocity of the particles will be overridden. At its $$anonymous$$imum bounce value, the particles will slide across the surface of the mesh, but travel no further.
In a mesh more complex than any primitive shape provided by the Particle System Force Field, you will be forced to fake this effect by placing multiple Force Fields to pull particles past where they slide off the mesh's surface. This is inherently inaccurate, you have to deal with multiple Force Fields interfering with each other and this is multiple Force Fields per Particle System. If particles come in from another direction, they slide off the mesh's surface at different locations and need to be pull in a different direction, hence you have to set up another group of Force Fields. And because this fake effect relies on knowing where particles come from ahead of time, the illusion will break as soon as the particle system's position changes during runtime.
This is ultimately a solution to create a fake effect for something as straightforward as making particles behave like real air flow being blown against a solid surface.
Your answer
Follow this Question
Related Questions
How to detect which exact particle element from a particle system hit a collider? 0 Answers
Unity 2D Particle System's collider doesn't trigger other colliders for scripts. 0 Answers
How to make OnParticleCollision affect multiple GameObject 1 Answer
Adjusting OnTriggerEnter2D() for OnParticleTrigger() 0 Answers
Let Particles sit on Collider without triggering callback - OnParticleCollisionEnter? . 1 Answer