using { /Fortnite.com/AI }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/Diagnostics }
# CUSTOM NPC BEHAVIOR — teach a villager to flee when hurt.
#
# An npc_behavior is a Verse class that rides ON TOP of an NPC's built-in brain.
# You attach it to an NPC Character Definition; OnBegin runs the moment the
# character is simulating. Unlike a creative_device, an npc_behavior gets a
# handle to its OWN character through GetAgent[] / GetFortCharacter[], then drives
# it with the navigatable and focus interfaces.
#
# This villager stands still until something damages them — then it sprints away
# from the attacker and keeps its eyes locked on the threat the whole time.
fleeing_villager := class(npc_behavior):
# How far to run when spooked (centimeters).
FleeDistance : float = 1200.0
# OnBegin runs when the NPC enters the simulation. Wire up its damaged event.
OnBegin<override>()<suspends> : void =
if:
Agent := GetAgent[]
Character := Agent.GetFortCharacter[]
then:
Character.DamagedEvent().Subscribe(OnDamaged)
Print("Villager is on patrol duty... nervously.")
Verse Library
verse
03 Standalone
Makes an NPC sprint away from attackers when hit and keep eyes on the threat.
verse-library/verse-npc-custom-behavior/03-standalone.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.