Verse Library verse

01 Npc States And Verse

Makes NPCs automatically chase the player who damaged them using navigation events.

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

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/understanding-npc-behaviors-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/uefn/understanding-npc-behaviors-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[]

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