Verse Library verse

01 Npc States And Verse

Defines NPC behavior that tracks attackers and navigates toward them when damaged.

extracted-snippets/documentation/en-us/fortnite/understanding-npc-behavior-in-unreal-editor-for-fortnite/01-npc-states-and-verse.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/understanding-npc-behavior-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/fortnite/understanding-npc-behavior-in-unreal-editor-for-fortnite.md
# Section:    NPC States and Verse
using { /Fortnite.com/AI }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
on_damaged_behavior<public> := class(npc_behavior):
# This function runs when the NPC is spawned in the world and ready to follow a behavior.
OnBegin<override>()<suspends>:void=
if:
Agent := GetAgent[]
FortCharacter := Agent.GetFortCharacter[]
then:
# Subscribe the character's damaged event to OnDamaged
FortCharacter.DamagedEvent().Subscribe(OnDamaged)
# When the NPC is damaged, start chasing the character
# that instigated the damage
OnDamaged(DamageResult:damage_result):void=
Instigator := DamageResult.Instigator
if:
# Get the Agent and the Navigatable interface
Agent := GetAgent[]
Character := Agent.GetFortCharacter[]
Navigatable := Character.GetNavigatable[]
# Get the agent that instigated the damage
InstigatingAgent := agent[Instigator?]
then:
# Start navigating to the InstigatingAgent
NavigationTarget := MakeNavigationTarget(InstigatingAgent)

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.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in