So I’m struggling with TargetUnreachable at the moment when setting the HRP CFrame to lookAt a part.
The thing is, it doesn’t seem that the HRP’s orientation seems to even affect the pathfinding because setting auto rotate to false changes nothing.
However, the issue comes from actually setting the CFrame lookat to face the point.
self.npc.HumanoidRootPart.CFrame = CFrame.lookAt(self.npc.HumanoidRootPart.Position, goalPosition)
The AI errors with TargetUnreachable (I’m using SimplePath) and as a result doesn’t move.
This seems really odd and any help is appreciated,
Here’s a sample of the code that using pathfinding.
function Agent:Patrol()
if self.patrolPath and not self.patrolling then
self.patrolling = true
self.loadedAnimations.AIPatrol:Play()
local pathParts = self.patrolPath
print("PATROLING!")
local function moveTo()
local pathPartsC = pathParts:GetChildren()
if self.currentWP > #pathPartsC then
self.currentWP = 1
end
local goalPosition = pathParts:FindFirstChild(tostring(self.currentWP)).Position
self.path:Run(goalPosition)
--local lookAt = Vector3.new(goalPosition.X, self.npc.HumanoidRootPart.Position.Y, goalPosition.Z)
-- TweenService:Create(self.npc.HumanoidRootPart, TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {}):Play()
self.npc.HumanoidRootPart.CFrame = CFrame.lookAt(self.npc.HumanoidRootPart.Position, goalPosition)
local pathReached
local waypointReached
pathReached = self.path.Reached:Connect(function()
self.currentWP += 1
pathReached:Disconnect()
waypointReached:Disconnect()
moveTo()
end)
waypointReached = self.path.WaypointReached:Connect(function()
if not self.patrolling then
self.path:Stop()
if waypointReached then
waypointReached:Disconnect()
end
if pathReached then
pathReached:Disconnect()
end
return
end
end)
local errorPath
errorPath = self.path.Error:Connect(function(err)
print(err)
errorPath:Disconnect()
self.patrolling = false
return
task.wait(3)
end)
end
moveTo()
end
end