Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add external force to particular particles?
#1
I created custom class from ObiExternalForce, added my solver. But it does not work. Do you have any idea how to add external force to particular particles?

Code:
using Obi;
using UnityEngine;

public class ObiSnakeExternalForce : ObiExternalForce
{
   public float k = 100;
   public override void ApplyForcesToActor(ObiActor actor)
   {
       var force= new Vector4(0, k, 0, 1);
       force[3] = 1;//actor.UsesCustomExternalForces ? 1 : 0;
       Oni.AddParticleExternalForce(actor.Solver.OniSolver, ref force, actor.particleIndices, actor.particleIndices.Length);
   }
}
Reply
#2
Bump.
Please, help  Triste
Reply
#3
(07-03-2018, 03:26 AM)dimmduh Wrote: Bump.
Please, help  Triste

Hi,

You should uncomment the //actor.UsesCustomExternalForces ? 1 : 0; line. Most actors do not use a custom way to apply external forces, in fact as of now only cloth does (forces are applied to cloth triangles instead of particles).

Also, Oni.AddParticleExternalForce takes an array of forces (Vector4[]), one for each particle index passed in the second argument. Since you're passing all particles in the actor (actor.particleIndices) but only one force, the call will have no effect. In fact, it can potentially crash your app since the size of the array you're passing does not match the size you SAY you're passing, which will most likely cause an access violation.

If you wanted to add force to a single particle instead, you should then call it like this:
Code:
Oni.AddParticleExternalForces(actor.Solver.OniSolver,new Vector4[]{force},actor.particleIndices[index],1); //index runs from 0 to actor.particleIndices.Length
Reply