I would like to write code such that each particle is affected by a force accelerating them towards a game object. Once a particle has collided with the game object, the particle is “killed.” I assume this is possible, many games that I know were made with unity do something like this (i.e. soul being absorbed into the vessel in Hollow Knight.) But I have not seen anything in the documentation for particles that would allow me to write code that does something like this. Essentially, I want to know what code could I write that would:
1.) accelerate each particle towards a gameobject
2.) check if the particles collided with that gameobject
3.) if they did, kill the particle
And I don’t know what functions I would use to apply a force to a particle, check if a particle collided with something, or kill a particle.
If anyone could tell me which functions I could use to do these things, that would be great.
Thanks in advance!
Some of this is built into the particle system already. Specifically the collision and killing of particles, it’s there in the particle system, maybe under “collision”. Not sure about the acceleration part but there are certainly velocity over time settings.
External Forces module and a ParticleSystemForceField game object could solve the force part of the problem.
And the Collision module for the collision part.
If you really wanna do it yourself in script though, there is Set/GetParticles for the particle properties, or use a fast c# job if you are using 2019.3. And for collisions there are methods to collide rays with gameobjects, but I don’t know specifically what they are. But if you use jobs, these won’t be available anyway, you’d have to do the maths yourself, which you’d be doing for the force stuff anyway.