How do I make a custom NPC patrol an area and only chase with line of sight?

Basically I am trying to create an NPC with custom behavior that patrols an area until they spot a player, which then they target that player and once theyre close enough trigger a jumpscare. But I am a big newbie and with little to no experience in verse this is a headache, I have watched a youtube video but cannot get it to work properly.

rabbitAI := class(npc_behavior):

BehaviorHelp : behaviorhelper = behaviorhelper{}

MakeInvisible(InPlayer:agent)<suspends>: void=
    if(PlayerChar := InPlayer.GetFortCharacter[]):
        PlayerChar.Hide()
        spawn:
            MakeVisibleAfterDelay(PlayerChar)
MakeVisibleAfterDelay(PlayerChar:fort_character)<suspends>: void=
    Sleep(10.0)
    PlayerChar.Show()

OnBegin<override>()<suspends>:void=
    if:
        NPCAgent := GetAgent[]
        NPCChar := NPCAgent.GetFortCharacter[]

        NPCNav := NPCChar.GetNavigatable[]
        NPCFocus := NPCChar.GetFocusInterface[]
        NPCAnim := NPCChar.GetPlayAnimationController[]
    then:
        NPCSpawnPoint := NPCChar.GetTransform().Translation

        loop:
            Sleep(0.1)
            if(NewTarget := BehaviorHelp.FindNearestTarget[NPCChar], NewAgent := NewTarget.GetAgent[], BehaviorHelp.Perception.DeviceSeesAgentEvent):
                spawn{NPCFocus.MaintainFocus(NewAgent)}
                NavTarget := MakeNavigationTarget(NewAgent)
                NPCNav.NavigateTo(NavTarget , ?MovementType := movement_types.Running, ?ReachRadius := 150.0)
                spawn{MakeInvisible(NewAgent)}
                spawn{BehaviorHelp.JumpscareAnim(NewAgent)}

this is the main script, i have another one which also serves as a creative device so i can link the cinematic sequence device to trigger the jumpscare, which doesnt work even though ive made sure it is properly set up in game!

behaviorhelper := class(creative_device):

@editable  Jumpscare : cinematic_sequence_device = cinematic_sequence_device{}
@editable  Perception : perception_trigger_device = perception_trigger_device{}

FindNearestTarget(FC : fort_character)<decides><transacts> : fort_character =
    var MaybeTarget : ?fort_character = false
    var CheckRange : float = 5000.0
    for(Player : GetPlayspace().GetPlayers(), PlayerFC := Player.GetFortCharacter[]):
        if:
            DistanceDifference := Distance(PlayerFC.GetTransform().Translation, FC.GetTransform().Translation) < CheckRange
            not PlayerFC = FC
        then:
            set MaybeTarget = option{PlayerFC}
            set CheckRange = DistanceDifference
    return MaybeTarget?

JumpscareAnim(Agent : agent)<suspends>:void=
    Jumpscare.Play(Agent)

You are very close

Step-by-step summary:

  • In Verse code, inside your rabbitAI class (inheriting from npc_behavior), use:
using { /Fortnite.com/Devices }
@editable Jumpscare : cinematic_sequence_device = cinematic_sequence_device{}

This lets you select the jumpscare cinematic device in the UEFN editor.

  • To trigger the cinematic animation for a player or agent, call:
Jumpscare.Play(NewAgent)

Replace NewAgent with the reference to the correct agent.

  • In UEFN:
  1. Open the NPC Spawner device’s details panel.
  2. Set the NPC Behavior Script Override to your rabbitAI Verse script.
  3. You’ll now see a new dropdown where you can assign your cinematic sequence device (for the jumpscare).

This connects everything so your NPC’s behavior script can play the assigned cinematic sequence for the correct agent when triggered.