Table of Contents

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

selfKey uint

The pushing body's key.

otherKey uint

The coincident body's key.

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

self Vector3

This NPC's position.

selfKey uint

This NPC's identity key; breaks the tie when two bodies coincide.

neighbours IReadOnlyList<Vector3>

Positions of nearby NPC bodies.

neighbourKeys IReadOnlyList<uint>

Each neighbour's identity key, in the same order.

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.