Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Modifying Emitter
#2
(14-02-2020, 01:59 PM)ilterbilguven Wrote: Hi,

Current emitter kills particles by lifespan. I want emitter to kill by position (For example, if a particle's Y position is below -5).

I managed to kill by that, but now emitter isn't working properly after when a particle is killed. How can I fix this?

Here's my CustomEmitter:

Code:
namespace Obi
{
  [AddComponentMenu("Physics/Obi/Obi Emitter", 850)]
  [ExecuteInEditMode]
  public class CustomObiEmitter : ObiActor
  {
     .
     .
     .

     [SerializeField] private float[] _posYs;
     
     public override void LoadBlueprint(ObiSolver solver)
     {
        .

        _posYs = new float[particleCount];
        for (var i = 0; i < _posYs.Length; ++i)
           _posYs[i] = 1;
       
        .
     }

     .
     .
     .

     protected override void SwapWithFirstInactiveParticle(int index)
     {
        .
        _posYs.Swap(index, activeParticleCount);
     }


     public bool EmitParticle(float offset, float deltaTime)
     {
        .
       
        _posYs[activeParticleCount] = 1;
       
        .
        .
        .
     }


     public override void BeginStep(float stepTime)
     {
        .
        .
        .
       
        for (int i = activeParticleCount - 1; i >= 0; --i)
        {
           _posYs[i] = m_Solver.positions[i].y;

           if (_posYs[i] <= -5)
           {
              KillParticle(i);
           }
        }

        .
        .
        .
       
       
     }
  }
}

Why not simply setting the particle's life to zero when it meets the condition you want (y < -5) instead of modifying the emitter class itself? Huh
Reply


Messages In This Thread
Modifying Emitter - by ilterbilguven - 14-02-2020, 01:59 PM
RE: Modifying Emitter - by josemendez - 14-02-2020, 02:59 PM
RE: Modifying Emitter - by ilterbilguven - 14-02-2020, 03:56 PM