Pathfinding service?

I dont know what to do, my pathfinding script seems broken and idk why. Script is very basic and I cant believe I did a mistake… anyways here’s the video of my problem: robloxapp-20201215-1230437.wmv (2.3 MB) (dinosaur is spinning around and slowly proggresses to next point)
and here is my script:

wait(5) -- waiting for everything to load
-- some variables --
local service = game:GetService("PathfindingService")
local hum = script.Parent.Humanoid
local torso = script.Parent.Torso
-- just picking a random part and creating path --
local randomPart = game.Workspace.WalkPoints:GetChildren()[math.random(1, #game.Workspace.WalkPoints:GetChildren())]
local path = service:CreatePath()
path:ComputeAsync(torso.Position, randomPart.Position)
local waypoints = path:GetWaypoints()

-- making every waypoint visible for me --
for i, v in pairs(waypoints) do
	local part = Instance.new("Part", game.Workspace)
	part.Position = v.Position
	part.Anchored = true
	part.CanCollide = false
end
-- actual pathfinding part --
for i, v in pairs(waypoints) do
	hum:MoveTo(v.Position)
	if v.Action == Enum.PathWaypointAction.Jump then
		hum:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	hum.MoveToFinished:Wait()
end

Thanks for help!

1 Like

I think you should the WaypointReached event to check when the waypoint is reached or wait for the humanoid to be near enough.

EDIT:

Couldn’t find the path.WaypointReached page, but that event is mentioned in the pathfinding page.

1 Like

I dont see WaypointReached event on the page… but I see that they are using MoveToFinished()

Are you near the model? If so, do:

dinosaurModel.PrimaryPart:SetNetworkOwner(nil)
1 Like

thanks for the reply, but that doesn’t seem to fix the problem

What exactly is the problem? I can’t see the video because I’m on mobile.

so I have a dinosaur, which is spinning while moving between two waypoints and after few spins, makes preogression and go for the next one. (btw u can download urself VLC for phone, for opening video files)

Try making it so that it only goes ONE position, let’s see how it behaves when he’s going to one specific place.

1 Like

robloxapp-20201215-1348171.wmv (2.2 MB) At high WalkSpeed there is no problem, but at lower it gets stuck

I think I know why, because the you put a part to indicate the waypoints for the Dino to walk, and making it to think that it’s part that you need to jump over. Try removing the parts as indicators.

ok I commented out the instance of parts, but still doesn’t work

Try this:

wait(5)

local PathfindingService = game:GetService("PathfindingService")

local dinosaur = script.Parent -- Your model
local modelSize = dinosaur:GetExtentsSize()

local humanoid = dinosaur.Humanoid
local torso = dinosaur.Torso

local walkPoints = workspace.WalkPoints:GetChildren()
local randomPart = walkPoints[math.random(1, #walkPoints)]

local pathParams = -- If the dinosaur is bigger than a regular humanoid character
	{
		AgentRadius = modelSize.X;
		AgentHight = modelSize.Y;
		AgentCanJump = true;
	}

local path = PathfindingService:CreatePath(pathParams)
path:ComputeAsync(torso.Position, randomPart.Position)

local waypoints = path:GetWaypoints()

for _, waypoint in pairs(waypoints) do
	local part = Instance.new("Part")
	part.Anchored = true
	part.CanCollide = false
	part.Position = waypoint.Position
	part.Parent = workspace
end

for _, waypoint in pairs(waypoints) do
	humanoid:MoveTo(waypoint.Position)
	
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	
	humanoid.MoveToFinished:Wait()
end
1 Like

comment out the hum.MoveToFinished:Wait()
and see what happens because i think itll be moving to one of the waypoints then returning true and i think you might be finding a new path after the humanoid has reach its location hence the constant change in paths

Unfortunately pathParameters aren’t fixing the problem, thanks for the reply tho

That’s the same as directly moving dinosaur to the finsih point, but yes there is no spinning in that case