Hello! I Am Helping My Friend Make A Survival Type Game, And I Need An Enemy That Always Chases The Nearest Player (Kinda Like Evade)
I Have Been Searching For Over An Hour, But Nothing Works Or It’s Outdated (Mostly Looking For Ones With PathFinding)
So If Anyone Can Help Me! It Would Be Much Appreciated!
Also I Have No Idea How To Use Pathfinding , If I Did I Would Do This Myself.
2 Likes
Please, search PathfindingService on the Roblox Documentation.
That may help you.
3 Likes
This tutorial is the one I always reccomend people, it really explains the code in detail and, as far as I know, still works
4 Likes
local Pathfind = game.PathfindingService
while wait(0.1) do
local human = [humanoid here]
local pos = human.RootPart.Position
local target = nil
local targetDistance = math.huge
local path = Pathfind:CreatePath()
local op = OverlapParams.new()
op.FilterType = Enum.RaycastFilterType.Exclude
op.FilterDescendantsInstances = {[enemy here]}
for _, i in workspace:GetPartBoundsInRadius(pos, 1000, op) do
if i.Name == "HumanoidRootPart" then
path:ComputeAsync(pos, i.Position)
if (i.Position-pos).Magnitude < targetDistance and path.Status == Enum.PathStatus.Success then
target = i.Position
targetDistance = (i.Position-pos).Magnitude
end
end
end
path:ComputeAsync(pos, target)
if target then
local waypoint = path:GetWaypoints()[12]
if waypoint.Action == 1 then
human.Jump = true
end
human:MoveTo(waypoint.Position)
end
end
1 Like
Huh, I keep getting an error,
attempt to index nil with 'Status'
woops, i forgot computeAsync doesn’t return a path
Anyway to fix it? AI Is one of the things im trash at, So i have no idea whats happening.
it should work now, just made it compute the path before checking for its status
Wait What Does It Mean By Unable to cast PathWaypoint to Vector3
??
Am i missing something?
i forgot :GetWaypoints()
returns PathWaypoints and not Vector3s
1 Like
BTW Do i need to add any patrol points? or do anythin else?
not unless it to move around when it can’t find anyone
Yeah my friend wanted to make this always chase the nearest player or smth
so ill test it and tell you if it does not work
So… Uhhh… The Enemy Does Not Move. It Just Stands There, MENACINGLY!
probally tracking its own humanoid rootpart, you dont need to change its name i added a filter to the detect thing so that it cant detect itself
Do i need to add the humanoid, HRP or just the model of the enemy to the filter?
put the model in the curly brackets here
1 Like
It works but… Its very janky.
First Of All - It Only Moves When I Push It.
Second Of All - It Is Very… Weird.
1 Like
it seems like computing the path causes a lot of lag between moves
Ah Okay. Anyway to fix it?
(AAAAAAAAAAAAA)