Vixen
02b45cc4
csharp
public sealed class PhysicsScene

The bridge: an ECS world on one side, a PhysicsWorld on the other, and one fixed step joining them.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Three passes, in this order and no other. Synchronize makes the physics world match what the components say — bodies created for new colliders, destroyed for removed ones, kinematic bodies driven towards their authored transforms. Step advances the simulation. Writeback copies the results back into LocalTransform and the velocity components. Doing them in any other order costs a step of latency at best and drives the simulation from stale poses at worst.

A body's entity should be a root. Physics works in world space and the bridge reads and writes LocalTransform, so an entity with a Parent has its local transform treated as though it were a world one — physics and the transform hierarchy then write the same component with different meanings, and the entity ends up wherever the last writer put it. Attach things to a body with a joint, or hang a child under the body rather than making the body a child.

The bridge holds no reference to any system. PhysicsSystems registers three thin systems that call these three methods, so a test, a tool or a headless server can drive the same passes without a SystemRunner.

Fields and properties (8)

  • public int CharacterCount

    How many entities have a character controller.

  • public World Entities

    The ECS world this bridges.

  • public PhysicsWorld World

    The simulation.

  • public PhysicsShapes Shapes

    The shapes bodies in this scene may use.

  • public int BodyCount

    How many entities have bodies.

  • public bool IsDisposed

    Whether Dispose has been called.

  • public ReadOnlySpan<EntityContactEvent> Contacts

    Contacts from the last Step, in entity terms.

  • public ReadOnlySpan<EntityTriggerEvent> Triggers

    Trigger crossings from the last Step, in entity terms.

Methods (10)

  • public bool TryGetCharacter(Entity entity, out CharacterController? controller)

    The controller an entity was given, if it has one.

  • public void StepCharacters(float deltaTime)

    Creates and destroys character controllers, then moves every one of them by one step.

  • public PhysicsScene(World entities, PhysicsWorldSettings? settings = null)

    Builds a bridge over an ECS world.

  • public PhysicsScene(World entities, PhysicsWorld world)

    Builds a bridge over an ECS world and a simulation somebody else owns.

  • public bool TryGetEntity(BodyHandle body, out Entity entity)

    The entity a body belongs to, if it still has one.

  • public bool TryGetBody(Entity entity, out BodyHandle body)

    The body an entity has, if it has one.

  • public void Synchronize(float deltaTime)

    Makes the simulation match the components: creates, destroys and rebuilds bodies, and pushes authored transforms and velocities in.

  • public PhysicsStepResult Step(float deltaTime)

    Advances the simulation and translates its events into entity terms.

  • public void Writeback()

    Copies the simulation's results back into components.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (16)

  • ArenaThirdPersonShooter
  • ArenaCameraOcclusionThirdPersonShooter
  • PlayerRigThirdPersonShooter
  • WeaponFireThirdPersonShooter
  • CharacterAllocationTestsVixen.Physics.Tests
  • CharacterMovementSystemVixen.Physics
  • CharacterSceneTestsVixen.Physics.Tests
  • MachineVixen.Net.Physics.Tests
  • PhysicsDebugDrawSystemVixen.Physics
  • PhysicsSceneTestsVixen.Physics.Tests
  • PhysicsStepSystemVixen.Physics
  • PhysicsSyncSystemVixen.Physics
  • PhysicsSystemsVixen.Physics
  • PhysicsWritebackSystemVixen.Physics
  • PredictedPlayerMovementVixen.Net.Physics
  • PredictedPlayerMovementTestsVixen.Net.Physics.Tests