Table of Contents

Class AISeparation

Namespace
FishMMO.Shared
Assembly
FishMMO.Shared.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, which the scene server gives every stacked instance separately (LocalPhysicsMode.Physics3D). 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

Resolve(Vector3, IReadOnlyList<Vector3>, float, float)

The velocity that moves self out of its neighbours' bodies.

public static Vector3 Resolve(Vector3 self, IReadOnlyList<Vector3> neighbours, float radius, float maxSpeed)

Parameters

self Vector3

This NPC's position.

neighbours IReadOnlyList<Vector3>

Positions of nearby NPC bodies.

radius float

Distance at which a neighbour starts to push, in metres.

maxSpeed float

Push speed when fully overlapped, in metres per second.

Returns

Vector3

A horizontal velocity, zero when nothing is inside the radius.