Hello !
So for the past few hours now I’m trying to do an aggressive AI that chases player using PathfindingService. Sometimes it works very well, no issues. And then sometimes the rig just doesn’t move for the exact same goal position. Is it because I’m doing pathfinding ?
Here’s a piece of the code for the movement:
function m.Run(ai,target:Part) --ai is an object from another module. target is the target hrp
local show_path = ai.settings.ShowPath
ai.values.Attacking = true
ai:SetGyroEnabled(false)
local hrp:Part = ai.objects.hrp
local humanoid: Humanoid = ai.objects.humanoid
local path = ps:CreatePath({
WaypointSpacing = 10,
AgentCanJump = ai.settings.CanJump,
})
local succ, err = pcall(function()
path:ComputeAsync(hrp.Position,target.Position)
end)
if succ then
local waypoints = path:GetWaypoints()
table.remove(waypoints,1) -- I removed it so the rig wont go too close from it's original position
if show_path then
for i, v in waypoints do
local sphere = Instance.new("Part")
game.Debris:AddItem(sphere,10)
sphere.Material = Enum.Material.Neon
sphere.Size = Vector3.one
sphere.Shape = Enum.PartType.Ball
sphere.Transparency = .7
sphere.Anchored = true
sphere.CanCollide = false
sphere.CastShadow = false
sphere.CanTouch = false
sphere.Position = v.Position
sphere.Parent = workspace
end
end
for i, v:PathWaypoint in waypoints do
humanoid:MoveTo(v.Position)
if v.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
end
end
And the result in both cases (both got the same goal position):
Working:
https://streamable.com/efu0zl
Not Working:
https://streamable.com/4ek11v
Can you help me plis ?