- Home /
Dust in light from flashlight
Good day! I'm trying to make dust in the light from the flashlight in the player's hand. I do this with the help of a Particle System with simulation in World Space. In general, if the player stands still, everything looks great. But when the player moves, the effect of drawing with particles occurs, associated with the lifetime of the particles. Is it possible to somehow track the exit of a particle outside the shape (in my case, a cone), and then remove it? Or can you only create a special collider (for example, from several spheres to get closer to the shape of a cone, since unfortunately there is no cone primitive in Unity) and track the exit of particles from it? Another option came to my mind: create a particle system that fills the entire level with dust particles. They are slightly visible by default. But when they hit the flashlight collider, the particles change to bright yellow.
Please tell me which of these options are feasible? Is there a smarter way to do this?
Answer by unity_bPYT4ES2DGHFVQ · Jan 17, 2021 at 09:23 AM
I realized that both options are easy to implement using the Trigger module of the Particle System. For those who in the future will look for an answer to the question of how to realize dust in the light of a flashlight, I will briefly tell you:
Note: two options are possible: the first is completely without scripting and, possibly, less resource-intensive than the second, and the second is more natural and plausible.
1) Create a cone using the Parabox Primitives asset (https://assetstore.unity.com/packages/tools/modeling/parabox-primitives-18576), add the Mesh Collider to it, turn off the Mesh Renderer.
First option (a):
2a) Create a System of Particles with simulation in the World Space, the shape is a Cone, with emission of particles by Volume
3a) Activate the Triggers module. Add the previously created cone to the Collider field. Inside - ignore, Outside - kill, Enter - ignore, Exit - kill.
This will create the effect of dust getting into the beam of light in front of your flashlight.
The second way (b):
2b) Create a global particle system so that it fills the entire game space. For example, if you have a room, stretch the Cube Shape to the size of your room.
3b) Activate the Triggers module. Add the previously created cone to the Collider field. Inside - Ignore, Outside - Ignore, Enter - Callback, Exit - Callback.
4b) Add the script from this page to this Particle System (https://docs.unity3d.com/2019.3/Documentation/Manual/PartSysTriggersModule.html). Customize the color for yourself. Done.
This method will create a real effect of a dusty space, particles of dust will be illuminated by your flashlight just like in real life.