Hey, to anyone reading, I’ll cut right to the point. I’m trying to have an efficient and at least more than semi-functional pathfinding for each and every “zombie” shown in the video.
Watch this video before reading on:
Briefly explaining how they path find to their target: I first just check if their target is in a straight line of sight from the zombie by creating a Ray. If so, I’ll simply have them move towards the target, otherwise it’ll move onto finding a more complex route to the target. If you rewatch the clip above, you’ll see that when I cut around corners or edges where zombies can no longer see me, they’ll calculate a new route with a slight problem. The issue is the fact they’ll bug back and this may repeat itself a lot several times with in a second as well making it almost impossible for zombies to ever even reach their target if they’re cutting corners excessively.
The code here shows how if the target has moved from the position of the final waypoint, then the zombie will then calculate a new path to the target. This is when the jittery back movement kicks in.
if (waypoints[#waypoints].Position - TargetHRP.Position).Magnitude > 15 then
zombie.Humanoid:MoveTo(zombie.HumanoidRootPart.Position)
break
end
I’m not sure if this is a cause of the zombies insane speed or not, however I can’t really change the speed as it is very necessary. So what solutions are there?
This post may feel rushed and all over the place, but if your interest is peaked, I’ll be more than willing to elaborate more to better get an explanation. Any help appreciated.
The code you provided is moving the zombie to it’s own position if I understood that right, so until the next loop of code runs the zombie will be in it’s previous position for a split second.
Also, is this definitely the cause of the problem? (did you comment it out and test).
Yes, I printed out many steps with in the code, and this is when it typically occurs. I need to figure out a way to to keep them from bugging out like that lol.
The reason they move back to their original position is so that then a new path can be calculated, however it doesn’t matter if I do or do not have that line of code, when a new path is computed, they still bug back.
Well it isn’t extremely necessary but the point is for it to stop where it’s at, therefore it goes to itself, and then it computes a new path. Even without this, they still bug back anyways.
it means that you have a script for searching the path and following it incorrectly, first make it without rays, and then, if everything is fine, add a ray or post all your code here
you have a little incomprehensible code, so make the code based on this example and then expand the functionality further
local reached
MoveToFinishedCon = npcHum.MoveToFinished:Connect(function(Reached)
if Reached then
reached = Reached
end
end)
while npcHum.Health > 0 do
task.wait()
local success, errorMessage = pcall(function()
path:ComputeAsync(npcHRP.Position, closestChrHRP.Position)
end)
if success and closestChrHRP and path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for i=2, #waypoints do
if waypoints[i].Action == Enum.PathWaypointAction.Jump then
npcHum:ChangeState(Enum.HumanoidStateType.Jumping)
end
npcHum:MoveTo(waypoints[i].Position)
local cnt = 0
reached = false
repeat
cnt+=1
--print(cnt)
task.wait()
until reached or cnt == 60 --
end
end
end
That is what it’s doing, however that isn’t efficient or effective, as I could get super far distances with in the time it may take for them to reach where I started.