Class AISeparation
- Namespace
- FishMMO.Server.Implementation.World.SceneServer.AI
- Assembly
- FishMMO.Server.dll
Keeps NPCs from standing inside one another without Unity's crowd avoidance.
public static class AISeparation
- Inheritance
-
AISeparation
- Inherited Members
Remarks
Unity's NavMesh crowd is one global simulation. A scene server stacks several instances
of the same world scene at the same coordinates, so with obstacle avoidance on, an NPC in
one instance steered around NPCs in every other — invisible shoves, tripped stuck timers,
spawner-mates in two instances pushing each other off their paths. Avoidance is therefore
off on every NPC agent (AIController.InitializeOnce) and this takes its place.
It is scene-scoped by construction: neighbours come from the NPC's own UnityEngine.PhysicsScene's AIBodyGrid, which is separate for every stacked instance. Attackers around one target are spaced by AICombatSlots; this only stops bodies overlapping in the wander, idle and approach cases the ring does not cover.
Methods
CoincidentPushDirection(uint, uint)
The horizontal direction selfKey pushes in when its body coincides
with otherKey's.
public static Vector3 CoincidentPushDirection(uint selfKey, uint otherKey)
Parameters
Returns
- Vector3
A unit horizontal direction.
Remarks
The pair's axis depends only on the unordered pair, and the lower key pushes along it while the higher pushes against it, so the two answers are exact opposites. Equal keys — which distinct NPCs never have, see IdentityKey — fall back to a fixed direction.
Resolve(Vector3, uint, IReadOnlyList<Vector3>, IReadOnlyList<uint>, float, float)
The velocity that moves self out of its neighbours' bodies.
public static Vector3 Resolve(Vector3 self, uint selfKey, IReadOnlyList<Vector3> neighbours, IReadOnlyList<uint> neighbourKeys, float radius, float maxSpeed)
Parameters
selfVector3This NPC's position.
selfKeyuintThis NPC's identity key; breaks the tie when two bodies coincide.
neighboursIReadOnlyList<Vector3>Positions of nearby NPC bodies.
neighbourKeysIReadOnlyList<uint>Each neighbour's identity key, in the same order.
radiusfloatDistance at which a neighbour starts to push, in metres.
maxSpeedfloatPush speed when fully overlapped, in metres per second.
Returns
- Vector3
A horizontal velocity, zero when nothing is inside the radius.