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

**URL:** <https://forums.unrealengine.com/t/how-do-i-make-a-custom-npc-patrol-an-area-and-only-chase-with-line-of-sight/2361442>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 27, 2025, 1:03am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-custom-npc-patrol-an-area-and-only-chase-with-line-of-sight/2361442 "2025-02-27T01:03:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yxg\_peep](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@yxg\_peep](https://forums.unrealengine.com/u/yxg_peep)\
**Post date:** [February 27, 2025, 1:03am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-custom-npc-patrol-an-area-and-only-chase-with-line-of-sight/2361442/1 "2025-02-27T01:03:26Z")

</div>

## 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):

```auto
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):

```auto
@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)

```

---

<div class="post-metadata">

**Author:** ![l\_i-jah](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@l\_i-jah](https://forums.unrealengine.com/u/l_i-jah)\
**Post date:** [August 11, 2025, 4:54am UTC](https://forums.unrealengine.com/t/how-do-i-make-a-custom-npc-patrol-an-area-and-only-chase-with-line-of-sight/2361442/2 "2025-08-11T04:54:56Z")

</div>

You are very close

### Step-by-step summary:

- **In Verse code** , inside your rabbitAI class (inheriting from npc\_behavior), use:

```auto
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:

```auto
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.
