Table of Contents

Class AbilityObjectSweep

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.dll

The swept shape query an AbilityObject resolves its hits with, in place of Unity's collision callbacks.

public static class AbilityObjectSweep
Inheritance
AbilityObjectSweep
Inherited Members

Remarks

Why an explicit query at all. An ability object moves by a closed-form position evaluated once per tick (AbilityMoveTransformAction) on a kinematic body, so OnCollisionEnter had two defects that cannot be fixed where it fires. It is not lag compensated — the physics step resolves against present positions while the caster's client rendered its peers in the past, and you cannot open a rewind scope around a step that has already run; and a body teleported once per tick tunnels straight through any target thinner than its per-tick step. Rewinding once for every projectile at once is not an option either, because each has a different caster with a different view offset. Hence one query per object, swept along the segment it just travelled, run inside that caster's own rewind.

Two queries, not one. A shape cast is documented not to register a collider it starts inside of. Measured against this editor it does report one for spheres and capsules — with a zero distance and a zero normal — but not dependably enough to build on, and a box cast is explicitly excluded. That blind spot is exactly the case a target which moved onto the object between ticks falls into, which is the case lag compensation exists to resolve correctly, so an overlap anchored at the segment start covers it outright. The same overlap is what lets a stationary object — one with no move action, whose segment has zero length and so admits no cast at all — resolve hits. Colliders both queries find are reported once.

Results are ordered before they are returned. A cast buffer is filled in broadphase order, which is neither reproducible across runs nor agreed between peers, and the caller caps the set by decrementing HitCount as it walks it — so the cap would otherwise choose arbitrary victims. Ordering is distance along the sweep, then the identity keys in TargetOrdering; never the Unity instance id, which is per-process.

Fields

MinimumSweepDistance

Segment length below which the sweep degenerates to a stationary overlap, in metres.

public const float MinimumSweepDistance = 0.0001

Field Value

float

Remarks

A cast needs a direction, and normalising a segment shorter than this produces noise rather than a heading. Well under a millimetre, so nothing that actually moves takes the overlap path.

Methods

CenterOffset(Collider, Transform)

The shape's centre, expressed as a world offset from its transform's own position.

public static Vector3 CenterOffset(Collider shape, Transform t)

Parameters

shape Collider
t Transform

Returns

Vector3

Remarks

The transform is already at the end of the segment, so the sweep cannot read the centre off it directly — it needs the offset to re-apply at the start position.

CollisionMaskForLayer(int)

The layers a collider on layer collides with, read from the project's collision matrix.

public static int CollisionMaskForLayer(int layer)

Parameters

layer int

Returns

int

Remarks

The matrix is what decided which contacts OnCollisionEnter ever saw, so deriving the query mask from it is what keeps the swept query hitting the same set of things the callback did. It is a project setting, identical on every peer, and global rather than per physics scene — so one cached row per layer is correct for every scene a server hosts.

ResetLayerMasks()

Drops the cached collision matrix so the next query re-reads it.

public static void ResetLayerMasks()

Remarks

The matrix is a project setting that can be edited between play sessions, and the cache is static so it survives a domain reload that did not recompile. Also the hook a test uses after changing Physics.IgnoreLayerCollision.

ResolveCapsule(CapsuleCollider, Transform, Vector3, out Vector3, out Vector3, out float)

The two sphere centres and the radius that describe a capsule collider in world space, centred on center.

public static void ResolveCapsule(CapsuleCollider capsule, Transform t, Vector3 center, out Vector3 point0, out Vector3 point1, out float radius)

Parameters

capsule CapsuleCollider
t Transform
center Vector3
point0 Vector3
point1 Vector3
radius float

Remarks

Radius scales by the larger of the two axes across the capsule and height by the axis along it, which is what Unity does; and the height is floored at a full diameter, because a capsule authored shorter than that is a sphere and a negative half-segment would put the two centres the wrong way round.

Sweep(PhysicsScene, Collider, Transform, Vector3, Vector3, LayerMask, List<AbilitySweepHit>)

Resolves everything the object's shape touched moving from from to to, in a deterministic order.

public static int Sweep(PhysicsScene physicsScene, Collider shape, Transform shapeTransform, Vector3 from, Vector3 to, LayerMask mask, List<AbilitySweepHit> results)

Parameters

physicsScene PhysicsScene

The scene's own physics world. Never the global UnityEngine.Physics API: a scene server hosts many scenes and the default one holds none of the relevant colliders.

shape Collider

The collider whose dimensions the sweep uses. A sphere, capsule or box is swept as itself; anything else (including null) degrades to a ray, which is thinner than the real shape but still swept and still compensated.

shapeTransform Transform

The live transform the shape's local centre, rotation and scale are resolved through — the ability object's own, which is already at to.

from Vector3

Where the object was when it last resolved hits.

to Vector3

Where the object is now.

mask LayerMask

Layers to query, normally from CollisionMaskForLayer(int).

results List<AbilitySweepHit>

Receives the ordered hits. Cleared first.

Returns

int

The number of hits written to results.

WorldHalfExtents(BoxCollider, Transform)

A box collider's world half extents.

public static Vector3 WorldHalfExtents(BoxCollider box, Transform t)

Parameters

box BoxCollider
t Transform

Returns

Vector3

WorldRadius(SphereCollider, Transform)

A sphere collider's world radius, scaled the way Unity scales one: by the largest component of the lossy scale, so a non-uniformly scaled sphere stays a sphere.

public static float WorldRadius(SphereCollider sphere, Transform t)

Parameters

sphere SphereCollider
t Transform

Returns

float