How to fix my Verse code for UEFN boss AI

I have a code for an AI boss that follows a player once a player activates a mutator zone. The problem is the AI enemy only targets one player instead of attacking the one who triggered the mutator zone. Can someone help me in fixing my code to do this?
Here is what I have so far:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Fortnite.com/Playspaces }

BossDevice := class(creative_device):

PlayerChar : ?agent = false

@editable
Bossprop : creative_prop = creative_prop{}

@editable
Zonedevice : mutator_zone_device = mutator_zone_device{}

ProptranslationAxis : vector3 = vector3:
X := 0.0
Y := 0.0
Z := -1.0

OnBegin():void=
Zonedevice.AgentEntersEvent.Subscribe(OnTriggered)

OnTriggered(Agent: agent):void =
spawn{FollowPlayer()}

FollowPlayer():void =

loop:
    Sleep(0.01)
    if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):
        Playerpostion : vector3 = FortCharacter.GetTransform().Translation
        Proptranslation : vector3 = Bossprop.GetTransform().Translation

        VectorToPlayer : vector3 = Playerpostion - Proptranslation

        RadiansVectorToPlayer: float = ArcTan(VectorToPlayer.X, VectorToPlayer.Y) - (PiFloat / 2.0)

        NewRotation : rotation =MakeRotation(axis := ProptranslationAxis, AngleRadians := RadiansVectorToPlayer)

        Bossprop.MoveTo(Playerpostion, NewRotation, 1.0)

    else:
         break

Hey! :wave:

Basically if I take a look at your code, you’re trying to get all players on the island, but as you said you only want the activating player.
I can’t show you the fixed code, but I can help you understand it a little bit more:

  • if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):

With this line of code you’re not accessing the player that activated the Mutator zone.

To achieve what you want, you have to do this instead:

  • You have to rather use the Agent that actually activated the mutator zone. You already used the Subscribe() event to start the function, but later on you didn’t do anything with that agent that you want to use.
1 Like

Sorry very new to this and trying to figure it out. So it has something to do with using the line where I used the subscribe function so I can save that particular player and put in in the line of code in the place of where if says PlayerList?

Not the Subscribe function, but when you call FollowPlayer inside OnTriggered you should be calling FollowPlayer(Agent) rather than FollowPlayer() since OnTriggered’s Agent is activating the trigger.

(adjusting FollowPlayer to accept an agent as well)

FollowPlayer(Agent: agent):void =

Then within FollowPlayer you can replace

if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):

with

if (FortCharacter := Agent.GetFortCharacter[]):
2 Likes