I’m making pathfinding bots that chase down the player once spotted, or in this case with this prototype, chase down a dummy target, but the problem is when one gets in front of another, or multiple in front of each other, they all seem to try and recalculate the path to avoid each other, but then just continue the path right after, it causes this weird stuttering effect that I need to fix.
Example
My bots use SimplePath, a module for pathfinding, and I’m open to other options, but at the moment I’m just confused at what I should do here.
I’ll leave the code here incase anyone can figure out if there’s some sort of issue with it, sorry about the spaghetti code, these are just prototypes though.
local enemy = script.Parent.Parent
local player = workspace.GameAssets.AIAssets.ObstacleCourse.desired
local path = simplePath.new(enemy)
-- create a loop to continuously fire the ray and update enemy position
while wait() do
-- create a new ray from the enemy's HumanoidRootPart to the player's HumanoidRootPart
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {enemy, workspace.DebugBlocks, workspace.Enemies}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(enemy.HumanoidRootPart.Position, (player.HumanoidRootPart.Position - enemy.HumanoidRootPart.Position).Unit * 1000, raycastParams)
-- debug to check where rays hit
--[[if raycastResult then
local hitPart = Instance.new("Part")
hitPart.Name = "RayHit"
hitPart.Anchored = true
hitPart.CanCollide = false
hitPart.Transparency = 0.5
hitPart.BrickColor = BrickColor.new("Bright red")
hitPart.Size = Vector3.new(0.5, 0.5, 0.5)
hitPart.CFrame = CFrame.new(raycastResult.Position)
hitPart.Parent = workspace.DebugBlocks
end]]
if raycastResult then
local hitObject = raycastResult.Instance
-- check if the hit object is a descendant of the player
if hitObject:IsDescendantOf(player) then
if path.Status ~= "Idle" then
path:Stop()
end
-- Move the enemy directly towards the player
enemy.Humanoid:MoveTo(player.HumanoidRootPart.Position)
else
-- use SimplePath to navigate towards the player
local goal = player.HumanoidRootPart.Position
path.Visualize = true
path:Run(goal)
end
end
end