I’m just starting to learn programming, but I don’t understand where the error is. Can someone help me? The context of what I’m trying to do is an AI that follows nearby players.
(here is all the code)
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation }
using { /Fortnite.com/Characters }
miniboss2 := class(creative_device):
@editable var Enemies : []creative_prop = array{}
var ClosestPlayer : player
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Sleep(30.0) # Espera 30 segundos
InitEnemies()
InitEnemies():void=
loop:
Sleep(0.1)
ClosestPlayer := FindClosestPlayer()
if ClosestPlayer:
for (X := 0..Enemies.Length - 1):
if (Enemy := Enemies[X]):
spawn:
FollowPlayer(Enemy)
FindClosestPlayer(): player =
ClosestPlayer := None
ClosestDistance := float.max
Players := GetPlayspace().GetPlayers()
for (Player := Players):
PlayerCharacter := Player.GetFortCharacter()
if PlayerCharacter:
PropLocation := PlayerCharacter.GetTransform().Translation
for (X := 0..Enemies.Length - 1):
if (Enemy := Enemies[X]):
EnemyLocation := Enemy.GetTransform().Translation
Distance := (EnemyLocation - PropLocation).Length()
if Distance < ClosestDistance:
ClosestPlayer := Player
ClosestDistance := Distance
return ClosestPlayer
FollowPlayer(Enemy : creative_prop)<suspends>:void=
MoveSpeed := 0.03
Sleep(0.1)
if ClosestPlayer:
PlayerCharacter := ClosestPlayer.GetFortCharacter()
if PlayerCharacter:
PropLocation := Enemy.GetTransform().Translation
PlayerLocation := PlayerCharacter.GetTransform().Translation
if (LookDirection := (PlayerLocation - PropLocation).MakeUnitVector()):
Yaw := RadiansToDegrees(ArcTan(LookDirection.Y, LookDirection.X)) - 90.0
Pitch := 0.0
Roll := 0.0
NewRotation := MakeRotationFromYawPitchRollDegrees(Yaw, Pitch, Roll)
# Movement
LerpLocation := Lerp(PropLocation, PlayerLocation, MoveSpeed)
FinalLocation := vector3{X := LerpLocation.X, Y := LerpLocation.Y, Z := 0.0}
Enemy.TeleportTo(FinalLocation, NewRotation)
else:
break