Crabkingclawbrain
Based on game build 722832 | Last updated: 2026-04-18
Overview
Crabkingclawbrain defines the AI behavior tree for the Crab King's claw entity in Don't Starve Together. This brain coordinates combat actions, boat-circling maneuvers, leash behavior, and wandering patterns. It integrates with the combat component for attack logic and knownlocations for spawn point tracking. The behavior tree uses a priority node structure where higher-priority actions (attacking) take precedence over movement behaviors. Configuration constants such as WAMDER_DIST, TARGET_LEASH_DIST, and CRABKING_RADIUS are defined at the module level (local variables) to tune movement constraints. These are not instance properties and cannot be modified per-entity.
Usage example
local CrabkingClawBrain = require("brains/crabkingclawbrain")
local inst = CreateEntity()
inst:AddComponent("combat")
inst:AddComponent("knownlocations")
inst.crabking = crabking_entity -- reference to parent Crab King
-- Instantiate and run the brain
local brain = CrabkingClawBrain(inst)
RunBrain(inst, brain)
Dependencies & tags
External dependencies:
behaviours/chaseandattack-- chase and attack behavior nodebehaviours/runaway-- flee behavior nodebehaviours/wander-- wandering behavior nodebehaviours/doaction-- action execution behavior nodebehaviours/attackwall-- wall attack behavior nodebehaviours/panic-- panic behavior nodebehaviours/minperiod-- minimum period behavior nodebehaviours/leash-- leash constraint behavior nodebehaviours/leashandavoid-- leash with avoidance behavior node
Components used:
combat-- checksInCooldown(), accessestargetandattackrangepropertiesknownlocations-- callsGetLocation()andRememberLocation()for spawn point trackinghull-- callsGetRadius()on platform entities for circle boat calculation
Tags:
- None identified
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
bt | table | nil | Behavior tree instance created in OnStart() |
Main functions
CrabkingClawBrain(inst)
- Description: Constructor that initializes the brain for the given entity instance. Calls parent Brain constructor.
- Parameters:
inst-- the entity instance this brain controls - Returns: Brain instance
- Error states: None
OnStart()
- Description: Initializes the behavior tree root node with priority-ordered behaviors. Sets up attack, circle boat, leash/avoid, and wander nodes in descending priority order.
- Parameters: None
- Returns: None
- Error states: Errors if
self.inst.components.combatorself.inst.components.knownlocationsare not present on the entity.
OnInitializationComplete()
- Description: Records the entity's current world position as the "spawnpoint" location for wander behavior reference.
- Parameters: None
- Returns: None
- Error states: Errors if
self.instis nil or ifself.inst.components.knownlocationsis not present on the entity. Errors ifself.inst.Transformis nil when callingGetWorldPosition().
findavoidanceobjectfn(inst)
- Description: Returns the Crab King entity reference for avoidance calculations.
- Parameters:
inst-- the claw entity instance - Returns: Crab King entity instance or
nilifinst.crabkingis not set - Error states: None
AttackTarget(inst)
- Description: Creates an attack action if combat cooldown is ready, target exists, and target is within attack range. Faces the target before attacking.
- Parameters:
inst-- the claw entity instance - Returns:
BufferedActioninstance if attack conditions met,nilotherwise - Error states: Errors if
inst.components.combatis nil. Errors iftarget:GetPosition()returns nil (no guard beforeinst:FacePoint()call).
CircleBoat(inst)
- Description: Calculates a circular positioning point around the target's boat platform. Used for leash and avoid behavior to maintain distance while circling.
- Parameters:
inst-- the claw entity instance - Returns:
Vector3position for circling, ornilif target or platform not found - Error states: Errors if
inst.components.combatis nil. Errors ifplatform.components.hullis nil (no guard beforeGetRadius()call). Errors iftarget.Transformorplatform.Transformis nil (no guard beforeGetWorldPosition()calls).
Events & listeners
None.