Hey everyone,
I’m experiencing an issue with my NPC pathfinding system within a tunnel. This system includes two parts (Destination and Destination2), where the NPC sets a waypoint.
The problem I’m facing relates to the animation side of things, where the animation of the NPC noticeably staggers as it makes its way towards Destination2 (and slightly as it makes its way to Destination at the beginning).
When thinking of a solution, keep in mind that I’ve tried the following to no avail:
-
Tried replacing the floor of the tunnel as a flat part
-
Replacing all four sides of the tunnel as flat parts
-
Removing the blue path
-
Placing the system on the Baseplate (blue path included)
-
Just placing the base system on the Baseplate
-
Checked for any errors in the Output window (none)
Video:
Script:
local ServerStorage = game:GetService("ServerStorage")
local CueEncounter = ServerStorage:FindFirstChild("CueEncounter")
local PathfindingService = game:GetService("PathfindingService")
local NPC = game.Workspace.ShadowSelf
local Humanoid = NPC.Humanoid
local LowerTorso = NPC.LowerTorso
local function GetPath(Destination)
local Path = PathfindingService:CreatePath({
AgentRadius = 1.5,
AgentHeight = 4,
AgentCanJump = false,
Costs = {
Plastic = 1,
SmoothPlastic = 1,
Sandstone = math.huge,
Basalt = math.huge,
Neon = math.huge
}
})
Path:ComputeAsync(LowerTorso.Position, Destination.Position)
return Path
end
local function WalkTo(Destination)
local Path = GetPath(Destination)
for i, Waypoint in ipairs(Path:GetWaypoints()) do
Humanoid:MoveTo(Waypoint.Position)
Humanoid.MoveToFinished:Wait()
local AnimationId = "rbxassetid://16572772560"
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId
AnimationRun = Humanoid:LoadAnimation(Animation)
AnimationRun:Play()
end
end
local function PlayAnimation()
local AnimationId = "rbxassetid://16573138859"
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId
local AnimationKnifeDraw = Humanoid:LoadAnimation(Animation)
AnimationKnifeDraw:Play()
task.wait(2.5)
local HeldKnife = NPC.RightHand.HeldKnife
HeldKnife.Transparency = 0
AnimationKnifeDraw:Stop()
end
local function Encounter()
local Destination = workspace.Waypoints.Destination
local Destination2 = workspace.Waypoints.Destination2
Humanoid.WalkSpeed = 6
WalkTo(Destination)
AnimationRun:Stop()
PlayAnimation()
task.wait(1)
Humanoid.WalkSpeed = 15
WalkTo(Destination2)
end
CueEncounter.Event:Connect(function()
Encounter()
end)