Hello Devs ![]()
soooo my Pathfinding works on stationary but not moving targets the problem is the movetofinished: because without it he repaths to the player however he wont be abel to go stairs properly and ignores cost and about cost he for some reason ignores that water is massively dangerous idk why so i wann ask waht should i do to keep movetofinished to make him walk smart and repath if stuck but also that my npc can properly chase players and not walk to the old position wihle keeping movetofinished
local Moving = false
local RepathCount = 0
local function Movement(targetPosition,Running)
if isStunned.Value then return end
if Moving then return end
task.spawn(function()
Moving = true
if Running == nil then
hum:MoveTo(root.Position) -- cancel movement
hum.WalkSpeed = 0
StopMovementAnimations() -- to stop animation
Moving = false
return
end
if Npc.Torso:FindFirstChild("MoveSound") then
Movesound = Npc.Torso.MoveSound
Movesound.Looped = true
Movesound.Volume = 0.3
else
Movesound = Instance.new("Sound")
Movesound.Looped = true
Movesound.Parent = Npc.Torso
Movesound.Volume = 0.3
Movesound.Name = "MoveSound"
Movesound.SoundId = "rbxassetid://1181265898"
end
if Running then
hum.WalkSpeed = CharStats.SprintSpeed * CharStats.SpeedIncreaseDecrease
if WeaponStats.WeponClass == "Spear" then
--IdleTrack.Priority = Enum.AnimationPriority.Action2
end
if not runTrack.IsPlaying then
walkTrack:Stop()
runTrack:Play()
Movesound:Play()
Movesound.PlaybackSpeed = 1.4
end
else
hum.WalkSpeed = CharStats.BaseWalkSpeed * CharStats.SpeedIncreaseDecrease
if WeaponStats.WeponClass == "Spear" then
--IdleTrack.Priority = Enum.AnimationPriority.Action
end
if not walkTrack.IsPlaying then
runTrack:Stop()
walkTrack:Play()
Movesound:Play()
Movesound.PlaybackSpeed = 1
end
end
local Path = Pathfinding:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = true,
AgentJumpHeight = 10,
AgentMaxSlope = 45,
cost = {
CrackedLava = 2,
Cobbelstone = 1,
Brick = 1,
Grass = 3,
Ground = 2,
Mud = 2,
Slate = 1,
Rock = 2,
LeafyGrass = 1,
Climb = 0.5,
ClimbHelper = 0.4,
Stairs = 0.1,
BridgeHelper = 0.1,
DangerZone = math.huge,
Water = math.huge,
},
})
Path:ComputeAsync(root.Position, targetPosition.Position)
if Path.Status == Enum.PathStatus.Success then
local waypoints = Path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
local distance = (root.Position - targetPosition.Position).Magnitude
Path:ComputeAsync(root.Position, targetPosition.Position)
local part = Instance.new("Part")
part.Material = "Neon"
part.Anchored = true
part.CanCollide = false
part.Shape = "Ball"
part.Position = waypoint.Position
part.Parent = game.Workspace
if waypoint.Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(waypoint.Position)
local Reached = hum.MoveToFinished:Wait(3) -- Thats the problem if i remove he stupid
if not Reached then
Path:ComputeAsync(root.Position, targetPosition.Position)
waypoints = Path:GetWaypoints()
hum:MoveTo(root.Position)
return
end--if it stays he dosent follow player properly
if distance >= 70 then -- and distance check also
EnemyNpc = nil
closestEnemy = nil
closestDistance = math.huge
detected = false
Moving = false
hum:MoveTo(root.Position)
break
end
RunService.Heartbeat:Wait()
end
Moving = false
else -- here is it if succes failed
warn(Npc.Name .. " failed to pathfind.")
Moving = false
return
end
Moving = false
end)
end
has anyone an idea i literly read 20 forum post and tried it over and over agin and im just lost ![]()