Skip to content

NPC Behaviors

NPC behaviors are defined through Role files that specify AI states, sensors, actions, and motion controllers. The behavior system uses a hierarchical template/variant architecture for reusability.

  • DirectoryAssets/Server/NPC/Roles/
    • Directory_Core/
      • DirectoryTemplates/
        • Template_Predator.json
        • Template_Animal_Neutral.json
        • Template_Birds_Passive.json
        • Template_Swimming_Aggressive.json
      • DirectoryComponents/
        • DirectoryFlock/
        • (Reusable instruction components)
    • DirectoryCreature/
      • DirectoryLivestock/
        • Sheep.json
        • Cow.json
        • Horse.json
      • DirectoryMammal/
        • Wolf_Black.json
        • Bear_Grizzly.json
        • Fox.json
      • DirectoryCritter/
        • Mouse.json
        • Squirrel.json
      • DirectoryVermin/
        • Spider.json
        • Snake_Cobra.json
      • DirectoryMythic/
        • Yeti.json
        • Fen_Stalker.json
    • DirectoryUndead/
      • DirectoryZombie/
        • Zombie.json
        • DirectoryTemplates/
        • DirectoryComponents/
      • DirectorySkeleton/
        • Skeleton.json
    • DirectoryIntelligent/
      • DirectoryAggressive/
        • DirectoryGoblin/
        • DirectoryTrork/
        • DirectoryOutlander/
        • DirectoryScarak/
      • DirectoryNeutral/
        • DirectoryFeran/
        • DirectoryKweebec/
    • DirectoryVoid/

Base templates that define reusable behavior patterns. Cannot be used directly.

Template_Predator.json (excerpt)
{
"Type": "Abstract",
"Parameters": {
"Appearance": {
"Value": "Fox",
"Description": "Model to be used."
},
"MaxHealth": {
"Value": 100,
"Description": "Max health for the NPC."
},
"ViewRange": {
"Value": 24,
"Description": "The range from which the target will be seen."
}
},
"StartState": "Idle",
"DefaultNPCAttitude": "Ignore",
"DefaultPlayerAttitude": "Neutral"
}

Specific NPCs that inherit from templates and override specific parameters.

Wolf_Black.json
{
"Type": "Variant",
"Reference": "Template_Predator",
"Parameters": {
"Appearance": {
"Value": "Wolf_Black",
"Description": "Model to be used."
},
"DropList": {
"Value": "Drop_Wolf_Black",
"Description": "Drop Items."
},
"MaxHealth": {
"Value": 70,
"Description": "Max health for the NPC"
}
},
"Modify": {
"Appearance": { "Compute": "Appearance" },
"MaxHealth": 103,
"MaxSpeed": 10,
"AttitudeGroup": "PredatorsBig",
"Attack": "Root_NPC_Wolf_Attack",
"AttackDistance": 2.5
}
}

Reusable instruction blocks that can be referenced from multiple roles.

Component_Instruction_Attack_Sequence_Zombie.json
{
"Class": "Instruction",
"Interface": "Hytale.Instruction.AttackSequence",
"Type": "Component",
"Parameters": {
"AttackDistance": {
"Value": 3.25,
"Description": "The distance at which an NPC will execute attacks"
}
},
"Content": {
"Sensor": {
"Type": "Target",
"Range": { "Compute": "AttackDistance" },
"Filters": [{ "Type": "LineOfSight" }]
},
"Actions": [
{ "Type": "Attack", "Attack": "Zombie_Swing_Left" },
{ "Type": "Attack", "Attack": "Zombie_Swing_Right" },
{ "Type": "Attack", "Attack": "Zombie_Bite" }
]
}
}
FieldTypeDescription
TypestringRole type: Abstract, Variant, or Component
ReferencestringParent template to inherit from (Variant only)
ParametersobjectConfigurable parameters with defaults
ModifyobjectProperty overrides
StartStatestringInitial AI state (e.g., "Idle")
AppearancestringModel definition ID
DropListstringDrop table ID
MaxHealthintMaximum health points
FieldTypeDefaultDescription
DefaultNPCAttitudestring"Ignore"Default attitude toward NPCs
DefaultPlayerAttitudestring"Neutral"Default attitude toward players
AttitudeGroupstringGroup for attitude calculations
DisableDamageGroupsarray["Self"]Groups this NPC won’t damage

Attitude Values:

  • Hostile - Will attack on sight
  • Neutral - Will attack if provoked
  • Friendly - Won’t attack, may follow
  • Ignore - Completely ignores
FieldTypeDefaultDescription
MaxSpeedfloat8Maximum walking speed
RunThresholdfloat0.55Speed ratio for run animation
WanderRadiusfloat8Idle wander area radius
ClimbHeightint1Max block height to climb
FieldTypeDefaultDescription
ViewRangefloat24Sight detection range (blocks)
ViewSectorfloat120Field of view (degrees)
HearingRangefloat12Sound detection range
AbsoluteDetectionRangefloat4Guaranteed detection range
AlertedRangefloat28Extended range when alerted
FieldTypeDefaultDescription
AttackstringRoot interaction ID for attacks
AttackDistancefloat2.5Range to initiate attacks
AttackPauseRangearray[2, 3]Min delay between attacks
ChaseRelativeSpeedfloat1Speed multiplier when chasing
CombatBehaviorDistancefloat5Range for combat movement
CombatStrafeWeightint10Probability of strafing
CombatDirectWeightint10Probability of direct charge
CombatBackOffAfterAttackbooltrueBack away after attacking
FieldTypeDefaultDescription
LeashDistancefloat20Soft leash radius
HardLeashDistancefloat60Absolute max distance
LeashMinPlayerDistancefloat4Min distance before giving up
LeashTimerarray[3, 5]Time before returning home
LeashRelativeSpeedfloat0.6Speed when returning

NPCs use a state machine for behavior control.

StateDescription
IdleDefault wandering/resting behavior
SleepSleeping (reduced detection)
Sleep.NapShort daytime nap
AlertedDetected potential threat
CombatActive combat engagement
Combat.ChasePursuing target
Combat.MaybeDeciding whether to fight
Combat.MessageBroadcasting attack to flock
SearchLooking for lost target
Search.ConfusedJust lost target
Search.ProwlActively searching
Search.InvestigateChecking disturbance
ReturnHomeReturning to spawn point
FleeRunning away from threat
PanicFleeing unknown damage source
State transition example
{
"StateTransitions": [
{
"States": [
{ "From": ["Idle"], "To": ["Sleep"] }
],
"Actions": {
"Reference": "Component_ActionList_Sleep"
}
},
{
"States": [
{ "From": ["Sleep"], "To": ["Alerted", "Idle"] }
],
"Actions": {
"Reference": "Component_ActionList_Wake"
}
},
{
"States": [
{ "To": ["Idle"], "From": [] }
],
"Actions": [
{ "Type": "ReleaseTarget" },
{ "Type": "ResetInstructions" }
]
}
]
}

Instructions define behavior logic using sensors, actions, and motion controllers.

{
"Instructions": [
{
"Sensor": { "Type": "State", "State": "Idle" },
"Instructions": [
{
"Sensor": { "Type": "Damage", "Combat": true },
"Actions": [
{ "Type": "State", "State": "Combat" }
]
}
]
}
]
}
FieldTypeDescription
SensorobjectCondition to trigger this instruction
InstructionsarrayNested instructions
ActionsarrayActions to execute
ActionsBlockingboolWait for actions to complete
ActionsAtomicboolExecute all actions together
BodyMotionobjectMovement behavior
HeadMotionobjectHead/look behavior
ContinueboolContinue to next instruction
ReferencestringInclude component by ID
ModifyobjectOverride component parameters
WeightintRandom selection weight
Enabledstring/boolEnable condition

Sensors detect conditions to trigger behaviors.

{
"Sensor": {
"Type": "Mob",
"GetPlayers": true,
"GetNPCs": false,
"Range": 15,
"LockOnTarget": true,
"Filters": [
{ "Type": "LineOfSight" },
{ "Type": "ViewSector", "ViewSector": 120 }
],
"Prioritiser": {
"Type": "Attitude",
"AttitudesByPriority": ["Hostile"]
}
}
}
TypeDescription
AnyAlways triggers
StateCheck current AI state
TargetCheck locked target properties
MobDetect NPCs or players
PlayerDetect players specifically
DamageReact to incoming damage
BeaconReceive flock communication
LeashCheck distance from spawn
TimeCheck time of day
FlagCheck boolean flag
TimerCheck named timer
EvalEvaluate expression
NavCheck navigation state
FlockLeaderCheck if flock leader exists
ReadPositionCheck stored position
FilterDescription
LineOfSightUnobstructed view to target
ViewSectorTarget within field of view
NPCGroupFilter by NPC group membership
AttitudeFilter by attitude
MovementStateTarget movement state
StandingOnBlockTarget standing on block type
HeightDifferenceVertical distance check
FlockCheck flock membership
SpotsMeTarget can see this NPC

Actions execute behaviors when sensors trigger.

{ "Type": "State", "State": "Combat" }
{ "Type": "ResetInstructions" }
{ "Type": "ReleaseTarget" }
TypeDescription
StateChange AI state
AttackExecute attack interaction
PlayAnimationPlay animation on slot
SpawnParticlesSpawn particle effect
TimeoutDelayed action execution
TimerStartStart named timer
TimerRestartRestart named timer
SetFlagSet boolean flag
BeaconSend message to NPCs
FlockBeaconSend message to flock
JoinFlockJoin target’s flock
SetLeashPositionUpdate spawn position
StorePositionStore position in slot
CrouchToggle crouching
SetStatModify NPC stat
SequenceExecute actions in order

Motion controllers define how NPCs move.

{
"MotionControllerList": [
{
"Type": "Walk",
"MaxWalkSpeed": 9,
"Gravity": 10,
"MaxFallSpeed": 15,
"MaxRotationSpeed": 360,
"Acceleration": 15,
"RunThreshold": 0.55
}
]
}
{
"BodyMotion": {
"Type": "Seek",
"SlowDownDistance": 2,
"StopDistance": 1.2,
"RelativeSpeed": 0.5,
"AbortDistance": 80,
"UsePathfinder": true
}
}
{
"BodyMotion": {
"Type": "Flee",
"SlowDownDistance": 15,
"StopDistance": 16,
"RelativeSpeed": 0.68
}
}
{
"HeadMotion": {
"Type": "Watch"
}
}
{
"HeadMotion": {
"Type": "Aim",
"Spread": 0,
"HitProbability": 1,
"RelativeTurnSpeed": 1.5
}
}

Define damage and effects for NPC attacks.

Wolf_Black.json InteractionVars
{
"_InteractionVars": {
"Melee_Start": {
"Interactions": [
{
"Parent": "Wolf_Bite",
"Effects": {
"ItemPlayerAnimationsId": "Wolf_Black_Default",
"ItemAnimationId": "Bite"
},
"RunTime": 0.167
}
]
},
"Bite_Damage": {
"Interactions": [
{
"Parent": "Wolf_Bite_Damage",
"DamageCalculator": {
"Type": "Absolute",
"BaseDamage": { "Physical": 27 },
"RandomPercentageModifier": 0.1
},
"DamageEffects": {
"Knockback": { "Force": 1 }
}
}
]
}
}
}

For friendly/tameable NPCs:

FieldTypeDescription
AttractiveItemsarrayItems that attract this NPC
LovedItemsarrayItems that guarantee following
ChanceToTurnFriendlyintBase befriend chance (%)
ChanceToTurnFriendlyWithAttractiveItemintBefriend chance with item (%)
FriendlyOverrideTimeintFriendly duration (seconds)
GrazingBlockSetstringBlock type to graze on
FoodBlockSetstringBlock type to eat
FoodItemSetarrayDropped items to eat
GreetAnimationstringAnimation when greeting
WeightGreetintChance to greet
WeightFollowintChance to follow
WeightFollowItemintChance to follow item
WeightIgnoreintChance to ignore
Sheep.json (excerpt)
{
"Modify": {
"IsHarvestable": true,
"HarvestDropList": "Drop_Sheep_Harvest",
"HarvestInteractionContext": "Shear",
"HarvestModelSlot": "Fleece",
"HarvestModelAttachmentHarvestable": "Wool",
"HarvestModelAttachmentHarvested": "",
"HarvestTimeout": ["PT11H", "PT14H"],
"HarvestParticles": "Sheep_Wool_Shear",
"HarvestSound": "SFX_Sheep_Sheared",
"ProduceItem": "Ingredient_Poop"
}
}

NPCs can form flocks for coordinated behavior.

{
"FlockArray": ["Wolf_Black"],
"FlockSpawnTypes": { "Compute": "FlockArray" },
"FlockAllowedNPC": { "Compute": "FlockArray" },
"ApplySeparation": true,
"SeparationDistance": 2.5,
"SeparationWeight": 1.2
}
{
"Sensor": {
"Type": "Beacon",
"Message": "Flock_Attack",
"TargetSlot": "LockedTarget",
"Range": 80
},
"Actions": [
{ "Type": "State", "State": "Combat.Maybe" }
]
}
{
"Actions": [
{
"Type": "FlockBeacon",
"Message": "Flock_Attack",
"SendTargetSlot": "LockedTarget"
}
]
}
{
"Parameters": {
"DayTimePeriod": {
"Value": [6.01, 17.99],
"Description": "The hour range considered daytime"
},
"AlwaysSleepAtNight": {
"Value": true,
"Description": "Whether to sleep through the night"
},
"TimidDuringDay": {
"Value": false,
"Description": "More cautious during day"
},
"NightFlavorAnimation": {
"Value": "Howl",
"Description": "Animation to play at night"
}
}
}
Zombie.json
{
"Type": "Variant",
"Reference": "Template_Aggressive_Zombies",
"Modify": {
"DropList": "Drop_Zombie",
"Appearance": "Zombie",
"MaxHealth": 49,
"IsMemory": true,
"MemoriesCategory": "Undead",
"_InteractionVars": {
"Melee_Damage": {
"Interactions": [
{
"Parent": "NPC_Attack_Melee_Damage",
"DamageCalculator": {
"BaseDamage": { "Physical": 18 }
}
}
]
}
},
"NameTranslationKey": { "Compute": "NameTranslationKey" }
},
"Parameters": {
"NameTranslationKey": {
"Value": "server.npcRoles.Zombie.name"
}
}
}
Sheep.json
{
"Type": "Variant",
"Reference": "Template_Animal_Neutral",
"Modify": {
"Appearance": "Sheep",
"FlockArray": ["Sheep", "Sheep_Lamb"],
"LovedItems": ["Plant_Crop_Lettuce_Item"],
"DropList": "Drop_Sheep",
"MaxHealth": 81,
"MaxSpeed": 6,
"ViewRange": 15,
"GreetAnimation": "Bleat",
"ChanceToTurnFriendly": 20,
"ChanceToTurnFriendlyWithAttractiveItem": 60,
"IsHarvestable": true,
"HarvestDropList": "Drop_Sheep_Harvest",
"HarvestInteractionContext": "Shear"
}
}
Wolf_Black.json (excerpt)
{
"Type": "Variant",
"Reference": "Template_Predator",
"Modify": {
"Appearance": "Wolf_Black",
"AttitudeGroup": "PredatorsBig",
"MaxHealth": 103,
"MaxSpeed": 10,
"ViewRange": 10,
"AlertedRange": 18,
"Attack": "Root_NPC_Wolf_Attack",
"AttackDistance": 2.5,
"CombatBackOffAfterAttack": true,
"CombatBackOffDistanceRange": [3, 5],
"ThreatenAnimation": "Howl",
"NightFlavorAnimation": "Howl",
"AlwaysSleepAtNight": false,
"TimidDuringDay": false
}
}
  1. Use templates - Inherit from core templates rather than duplicating behavior
  2. Use components - Extract reusable instruction blocks as components
  3. Test state transitions - Ensure all states have valid exit paths
  4. Balance detection ranges - ViewRange > AlertedRange > AbsoluteDetectionRange
  5. Configure leashing - Prevent NPCs from wandering too far
  6. Set appropriate attitudes - Match NPC faction and personality
  7. Use flock communication - Coordinate group responses to threats