Pathfinding on Character?

Can I use Pathfinding on a actual Player Character?

local function ForcePlayerWalk(Player, Position)
	local Path = PathfindingService:CreatePath({AgentRadius = 2, AgentHeight = 5, AgentCanJump = false})
	
	Path:ComputeAsync(Player.Character.HumanoidRootPart.Position, Position)
	local Waypoints = Path:GetWaypoints()
	
	for _, Waypoint in pairs(Waypoints) do
		Player.Character.Humanoid:MoveTo(Waypoint.Position)
		
		Player.Character.Humanoid.MoveToFinished:Wait()	
	end
end

The for loop is not running at all.

You should be able to just fine. EDIT: If the player moves it’ll override the :MoveTo() function. This website seems to solve that problem pretty well though.

Have you checked Path.Status?

When should I check that?
30characters

Check the .Status right after you do your :ComputeAsync() If its anything other than success that would explain why you say the loop never runs.

I put in a print(Path.Status) before the for loop and it said no path.
Which is weird, because without the pathfinding a simple
MoveTo(Position works)

In that case, Roblox failed to find a valid path to your destination, meaning your waypoints will be nil as they dont exist in the first place.

How does this fail?
image

Is the Position argument that parts position? If so, its because the rest of the block is in the way. Make the block non-collideable. (Although I’m not sure if pathfinding ignores non collide parts. )

1 Like

Nah it’s the side of the block.
We got all that here

and running just the MoveTo function wtihout pathfinding works fine.

Try making the block non-collidable regardless and tell me if that works.

Also, it may not work because if you’re using CFrame.new(0, part.Size.Y/2, 0), that’ll get the top surface of the block, to get the side you’re going to want to modify that so it’s creating a CFrame with an offset that’s not along the Y-axis of the part.
For example: CFrame.new(0, 0, -part.Size.Z/2)

This works because :MoveTo isn’t calculating to see if the move is possible or not. It’s just gonna start moving towards a position regardless of any other potential variables.

Nah, that aint what I’m using…

local PartFace = {
		North = Part.CFrame:PointToWorldSpace(Vector3.new(0, 0, Part.Size.Z/2)),
		South = Part.CFrame:PointToWorldSpace(Vector3.new(0, 0, (Part.Size.Z/2)*-1)),
		West = Part.CFrame:PointToWorldSpace(Vector3.new(Part.Size.X/2, 0, 0)),
		East = Part.CFrame:PointToWorldSpace(Vector3.new((Part.Size.X/2*-1), 0, 0))
	}

Turning it to no-collide did work I think that’s because it’s literally a tiny bit in the block
image

1 Like

That makes sense. To fix that you could add an extra 2 studs away from the block face so the path won’t fail.

Changing your table to this should work.

local PartFace = {
		North = Part.CFrame * Vector3.new(0, 0, (Part.Size.Z/2)+2),
		South = Part.CFrame * Vector3.new(0, 0, (-Part.Size.Z/2)+2),
		West = Part.CFrame * Vector3.new((Part.Size.X/2)+2, 0, 0),
		East = Part.CFrame * Vector3.new((-Part.Size.X/2)-2, 0, 0)
	}
1 Like

I appreciate your help, I have actually forgoed the whole pathfinding thing, with the code I was using you could visually see the user stop and go, which I do not want.

1 Like