[V2] Any sample for forcefield?
[V2] Any sample for forcefield?
is there any sample for forcefield simulation? E.g a forcefield volume will affect any object that inside the volume.
Re: [V2] Any sample for forcefield?
Not at the moment, but querying the broad phase for bodies with overlapping bounding boxes is a good start. Something like:
where the BroadPhaseOverlapEnumerator is:
You could then walk over the overlaps and modify the velocity of any detected bodies.
The collision query demo shows how to detect bodies with contact-level precision. It's more complicated since it involves the CollisionBatcher.
Code: Select all
var broadPhaseEnumerator = new BroadPhaseOverlapEnumerator { Pool = BufferPool, References = new QuickList<CollidableReference>(16, BufferPool) };
Simulation.BroadPhase.GetOverlaps(queryBoundsMin, queryBoundsMax, ref broadPhaseEnumerator);
Code: Select all
struct BroadPhaseOverlapEnumerator : IBreakableForEach<CollidableReference>
{
public QuickList<CollidableReference> References;
//The enumerator never gets stored into unmanaged memory, so it's safe to include a reference type instance.
public BufferPool Pool;
public bool LoopBody(CollidableReference reference)
{
References.Allocate(Pool) = reference;
//If you wanted to do any top-level filtering, this would be a good spot for it.
//The CollidableReference tells you whether it's a body or a static object and the associated handle. You can look up metadata with that.
return true;
}
}
The collision query demo shows how to detect bodies with contact-level precision. It's more complicated since it involves the CollisionBatcher.