I want to make NPC WALK to EXACT position that was put in Humanoid:MoveTo().
From what I’ve seen so far NPC walks, but ALWAYS decides to stop just a moment before completing the path as showcased in the video. Those red and green parts have CanCollide, CanQuery and CanTouch disabled, being for debugging purposes only. Green shows where NPC should stop.
Here’s the code for making NPC move (Server):
local r_storage = game:GetService("ReplicatedStorage")
local s_storage = game:GetService("ServerStorage")
local r_events = r_storage:WaitForChild("Events")
local pathfiding = game:GetService("PathfindingService")
local v_soldier = workspace:WaitForChild("Soldier")
r_events:WaitForChild("Units"):WaitForChild("Move").OnServerEvent:Connect(function(player, pos)
print(player, pos)
local t_node = Instance.new("Part")
t_node.Size = Vector3.new(0.5, 0.5, 0.5)
t_node.Material = Enum.Material.Neon
t_node.Color = Color3.fromRGB(255, 74, 77)
t_node.Anchored = true
t_node.CanCollide = false
t_node.CanQuery = false
t_node.CanTouch = false
t_node.Parent = workspace
t_node.Position = pos
local t_path = pathfiding:CreatePath({
AgentCanJump = false,
AgentCanClimb = false,
AgentRadius = 0.2,
})
local t_waypoints
local success, errorMsg = pcall(function()
t_path:ComputeAsync(v_soldier:WaitForChild("Node").Position, pos)
end)
if success and t_path.Status == Enum.PathStatus.Success then
print("foundPath")
t_waypoints = t_path:GetWaypoints()
end
if t_waypoints then
local t_currentWaypoint = 0
local t_limit = table.maxn(t_waypoints)
repeat
t_currentWaypoint+=1
v_soldier.Humanoid:MoveTo(t_waypoints[t_currentWaypoint].Position)
v_soldier:WaitForChild("Humanoid").MoveToFinished:Wait()
until t_currentWaypoint == t_limit
end
t_node:Destroy()
end)
Is there any way to fix it or atleast different method that will allow to achieve the same thing?