2
\$\begingroup\$

I'm working on a game which involves streams of electrically-charged particles, being manipulated with electric and magnetic fields. Since I want a large number of small objects coming from an emitter and lasting a limited amount of time, a particle system seems like the way to go.

My only problem now is: how to apply the force? Suppose, for example, I have a charged object somewhere in the scene; I want to apply a force toward it, varying with the radius squared. If my particles were Rigidbodies, applying this force in the FixedUpdate would be easy; is there a way to do the same to an individual particle?

\$\endgroup\$
  • \$\begingroup\$ Since you can add RigidBody to the particle system, im second guessing myself. There's a chance you could turn that on, and have your charge areas as triggers, and apply the force from the charged object through the trigger event. If that's viable, ill update my answer below. \$\endgroup\$ – Stephan Nov 7 '18 at 16:14
  • \$\begingroup\$ @Stephan If that works, that would be perfect. \$\endgroup\$ – Draconis Nov 7 '18 at 16:16
3
\$\begingroup\$

In 2018.2, the only way to apply external forces is through Wind Fields or direct collisions with rigid bodies.

You will probably have luck by using the ShapeModule with a ShapeType of Mesh and MeshShapeType of Edge. You could then have the player manipulate the vertex positions of the mesh to create the field line along which the particle will travel.

If you're comfortable with using beta builds of Unity, the 2018.3b version introduces a new GameObject Component called ParticleSystemForceField. This allows you to define custom areas of forces to be applied to particle that enter the area.

A good demo of the experimental features is available in The Unity Particle System Update: Features, Tips and Beyond! recording of the Unite Seoul Conference, May 2018.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Note that you can also set the particle buffer directly through script if you want to manipulate particle positions/velocities or other properties in C# code. \$\endgroup\$ – DMGregory Nov 7 '18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.