Hello! I have a custom rig that I have created a pathfinding script for. The rig can pathfind fine, I just want to make it smoother on turns, remove the jittering shown at the end of the video, etc. How would I do this? (Side Note: The head jitters are in the animation, that isn’t a bug.)
The video:
External MediaMy code:
local Monster = script.Parent
local Humanoid = Monster:WaitForChild("Humanoid")
local Hrp = Monster:WaitForChild("HumanoidRootPart")
local PathService = game:GetService("PathfindingService")
local Debris = game:GetService("Debris")
local FollowPart = workspace:WaitForChild("FollowTestPart")
local RUN_INTERVAL = 1
local DebugFolder = Instance.new("Folder")
DebugFolder.Name = "PathDebugParts"
DebugFolder.Parent = workspace
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local Animations = Monster:FindFirstChild("Animations")
local Sounds = Monster:FindFirstChild("SFX")
local WalkAnim = Animations:WaitForChild("Walk")
local IdleAnim = Animations:WaitForChild("Idle")
local WalkTrack = Animator:LoadAnimation(WalkAnim)
local IdleTrack = Animator:LoadAnimation(IdleAnim)
local IsWalking = false
local IsIdle = false
WalkTrack:GetMarkerReachedSignal("Footstep1"):Connect(function()
local CloneFootstep = Sounds.Footstep:Clone()
CloneFootstep.Parent = Monster:FindFirstChild("Head"):FindFirstChild("SoundAttachment")
CloneFootstep:Play()
Debris:AddItem(CloneFootstep,CloneFootstep.TimeLength)
end)
WalkTrack:GetMarkerReachedSignal("Footstep2"):Connect(function()
local CloneFootstep = Sounds.Footstep:Clone()
CloneFootstep.Parent = Monster:FindFirstChild("Head"):FindFirstChild("SoundAttachment")
CloneFootstep:Play()
Debris:AddItem(CloneFootstep,CloneFootstep.TimeLength)
end)
task.spawn(function()
while true do
DebugFolder:ClearAllChildren()
local path = PathService:CreatePath({
AgentRadius = 18,
AgentHeight = 14,
AgentCanJump = false,
AgentJumpHeight = 0,
AgentCanClimb = false,
AgentMaxSlope = 45
})
path:ComputeAsync(Hrp.Position, FollowPart.Position)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
if IsWalking == false then
IsWalking = true
IsIdle = false
if IdleTrack then IdleTrack:Stop() end
if WalkTrack then WalkTrack:Play() end
end
for _, waypoint in ipairs(waypoints) do
local marker = Instance.new("Part")
marker.Anchored = true
marker.CanCollide = false
marker.Shape = Enum.PartType.Ball
marker.Size = Vector3.new(1, 1, 1)
marker.Position = waypoint.Position + Vector3.new(0, 1.5, 0)
marker.Color = Color3.fromRGB(0, 255, 0)
marker.Material = Enum.Material.Neon
marker.Parent = DebugFolder
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
if IsIdle == false then
IsIdle = true
IsWalking = false
if WalkTrack then WalkTrack:Stop() end
if IdleTrack then IdleTrack:Play() end
end
else
warn("Failed to compute path")
end
task.wait(RUN_INTERVAL)
end
end)