(Sorry for the video quality, I can’t upload very big files into here)
As you can see in the video above, my NPC can’t detect when something is moved in front of him. I mostly want to do this because if a player walked in front it wouldn’t look that good. Is there any way I can make it create a new path to avoid the part; while still not making it slow?
Here is my script:
local PathFindingService = game:GetService(“PathfindingService”)
local human = script.Parent:WaitForChild(“Humanoid”)
local torso = script.Parent:WaitForChild(“LowerTorso”)
local path = PathFindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.EndingPart.Position)
local waypoints = path:GetWaypoints()
local runAnim = human:LoadAnimation(script:FindFirstChild(“RunAnim”))
local jumpAnim = human:LoadAnimation(script:FindFirstChild(“JumpAnim”))
runAnim.Looped = true
local function jumping()
jumpAnim:Play()
wait(.5)
jumpAnim:Stop()
end
runAnim:Play()
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
spawn(jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait()
end