Table of Contents

Method CollideCapsule<TCallback>

Namespace
Box3D
Assembly
Box3D.NET.dll

CollideCapsule<TCallback>(Capsule, Vector3, ref TCallback, QueryFilter?)

Finds every surface a character capsule is touching, for the plane solver.

public void CollideCapsule<TCallback>(Capsule capsule, Vector3 origin, ref TCallback callback, QueryFilter? filter = null) where TCallback : struct, ICharacterCollisionCallback

Parameters

capsule Capsule

The character capsule, relative to origin.

origin Vector3

The world position the capsule is measured from.

callback TCallback

The callback, passed by reference so what it records survives the call.

filter QueryFilter?

Which shapes the capsule collides with, or null for everything.

Type Parameters

TCallback

The callback type. A struct, so gathering contacts every frame allocates nothing.

Examples

var gather = new GatherPlanes { Planes = planeBuffer };
world.CollideCapsule(capsule, position, ref gather);

var result = CharacterMover.SolvePlanes(desiredMove, planeBuffer.AsSpan(0, gather.Count));
position += result.Translation;
velocity = CharacterMover.ClipVelocity(velocity, planeBuffer.AsSpan(0, gather.Count));

Remarks

This is the first step of kinematic character movement. Feed the contacts to Box3D.CharacterMover.SolvePlanes(System.Numerics.Vector3,System.Span{Box3D.CollisionPlane}) to find where the character can actually go.

Prefer this over Box3D.PhysicsWorld.CastCapsule(Box3D.Capsule,System.Numerics.Vector3,System.Numerics.Vector3,System.Nullable{Box3D.QueryFilter}) for finding out what the character is touching: a cast tells you where it stops, these planes tell you what is in the way and in which direction.

Exceptions

ObjectDisposedException

The world has been disposed.