Skip to content

Custom Behaviors

Addon mods can add new AI tasks and entity behaviors on top of the base VS entity system. Heartwood provides several built-in behaviors that addons can enable; you can also write new ones.

Built-in behaviors (from Fauna)

These behaviors are implemented in the Fauna addon and can serve as reference implementations:

BehaviorClassDescription
Herd cohesionAiTaskHerdCohesionKeeps entities grouped within a radius
GrazeAiTaskGrazeRandom idle wandering for herbivores
Return homeAiTaskReturnHomeNavigate back to assigned den/burrow
Use denAiTaskUseDenEnter and rest inside a den entrance block

Built-in behaviors (from Wingspan)

BehaviorClassDescription
Boids flockingAiTaskBoidsFlockSeparation/cohesion/alignment flocking
TakeoffAiTaskTakeoffLaunch from perch to air
LandAiTaskLandDescend from air to perch
PerchAiTaskPerchIdle on a surface
Feeder approachAiTaskApproachFeederWalk/fly to a filled bird feeder
HuntAiTaskHuntBirdPredatory bird hunting smaller species

Writing a custom AI task

AI tasks in VS extend AiTaskBase. See the VS modding wiki and vsessentialsmod source for examples.

csharp
public class AiTaskMyBehavior : AiTaskBase
{
    public AiTaskMyBehavior(EntityAgent entity) : base(entity) { }

    public override bool ShouldExecute() { /* when to activate */ }
    public override void StartExecute() { /* on activation */ }
    public override bool ContinueExecute(float dt) { /* return false to end */ }
}

Register it in AssetsFinalize() so it's available for entity JSON:

csharp
api.RegisterEntityBehaviorClass("mymod:mybehavior", typeof(MyEntityBehavior));

Released under the MIT License.