Obi Official Forum
Help How to prevent granular from colliding with themselves - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Help How to prevent granular from colliding with themselves (/thread-4055.html)



How to prevent granular from colliding with themselves - huangfeihu - 20-11-2023

How to prevent the granular themselves from colliding and only collide with the set layer


RE: How to prevent granular from colliding with themselves - josemendez - 20-11-2023

(20-11-2023, 03:25 AM)huangfeihu Wrote: How to prevent the granular themselves from colliding and only collide with the set layer

Hi!

By default granulars always collide with themselves, that's what makes them granulars. Otherwise they'd just be "expensive particles".

If you want to disable granular self-collisions however, you can modify their phase flags upon emission:

Code:
void Awake()
{
    GetComponent<ObiEmitter>().OnEmitParticle += Emitter_OnEmitParticle;
}

void Emitter_OnEmitParticle (ObiEmitter emitter, int particleIndex)
{
    if (emitter.solver != null)
        {
                int solverIndex = emitter.solverIndices[particleIndex];
                
                var group = ObiUtils.GetGroupFromPhase(emitter.solver.phases[solverIndex]);

                // set flags to zero instead of ObiUtils.ParticleFlags.SelfCollide
                emitter.solverphases[solverIndex] = ObiUtils.MakePhase(group, 0);
    }        
}

kind regards,