GetFocusInterface

method
(InCharacter: fort_character).GetFocusInterface<public>()<transacts><decides>: focus_interface

Get the focus_interface interface for the specified character.

Module
/Fortnite.com/AI
Declared in
AI
Source
fortnite

Used in

OnDamaged(Result : damage_result) : void =
        if:
            Agent := GetAgent[]
            Character := Agent.GetFortCharacter[]
            Navigatable := Character.GetNavigatable[]
            Focus := Character.GetFocusInterface[]
            Attacker := agent[Result.Instigator?]
            AttackerChar := Attacker.GetFortCharacter[]
        then:
            MyPos := Character.GetTransform().Translation
            ThreatPos := AttackerChar.GetTransform().Translation
            # Direction pointing FROM the threat TO us, normalized, then pushed out.
            Away := (MyPos - ThreatPos)
            FleePoint := MyPos + Away * FleeDistance
            Target := MakeNavigationTarget(FleePoint)
            Print("Villager spooked — fleeing!")
            # Keep looking at the attacker while we run (focus never completes
            # on its own, so spawn it as its own fiber).
            spawn{ Focus.MaintainFocus(Attacker) }
            spawn{ RunAway(Navigatable, Target) }
NpcSystem / Npc Data verse-source
NewNPCData := npc_data{
            InAgent := InAgent
            InCharacter := InCharacter
            InBehavior := InAgent.GetNPCBehavior[]
            Navigatable := InCharacter.GetNavigatable[]
            InFocus := InCharacter.GetFocusInterface[]
            InAnimation := InCharacter.GetPlayAnimationController[]
            # Initialize new NPCSessionData
            SessionData := npc_session_data{
                SpawnPoint := InCharacter.GetTransform().Translation
                LastKnownPosition := InCharacter.GetTransform().Translation
            }
            # Initialize new NPCPersistentData
            SavedData := npc_persistent_data{
                NpcName := "Unknown"  # Unknown NPC name set during runtime
                SpawnPoint := InCharacter.GetTransform().Translation
            }
NpcSystem / Npc Statemachine verse-source
SearchDuration := GetRandomFloat(2.0, 5.0)
                # Make the NPC face the direction of the player
                                block:
                                    InAgent.GetFortCharacter[].GetFocusInterface[].MaintainFocus(PlayerDirection)
                                    Sleep(SearchDuration)
                                # Move the NPC to the random location
                                MoveNPCTo(?MoveToLocation:=RandomLocation, ?MovementType:=(/Fortnite.com/AI/movement_types:)Walking, ?Radius:=ActivationRange, ?AllowPartialPath:=true, ?Accuracy:=100.0, ?WaitTime:=5.0)
                                
                                if (DebugDraw?):
                                    DebugNpc("Player within Search Range, starting SearchForPlayer", ?Duration := AIDebugDrawTime, ?TextColor := NamedColors.CadetBlue)
                                
                                # Wait for a random amount of time before searching again
                                
                                Sleep(SearchDuration)
                                
                                # Check if the state has changed during the search
                                if (CurrentState <> CurrentStateOptions.Searching):
                                    break
                        else:
                            if (DebugDraw?):
                                DebugNpc("Player out of Search Range, starting SearchForPlayer", ?Duration := AIDebugDrawTime, ?TextColor := NamedColors.CadetBlue)
                            
                            # Wait for a cooldown timer before searching again
                            CooldownTimer(?Cooldown:=3.0)