Help With Pathfinding Script To Move Robot Vehicle Over Minor Changes in Snow Terrain Elevation

Hello All,

I have a little robot that I am trying to automatically move around a snow terrain map using a pathfinding script. The problem is the robot seems to get stuck at any small change in elevation.

When the setup is nothing more than a baseplate, the robot can get to the goal (a pink block) just fine. If those objects are then transferred over to the snow terrain, the robot is constantly stuck after going only a few feet.

In my game I want to be able to create multiple points across the entire terrain for the robot to visit, one after another; point 1, then go to point 2, then point 3 … and so forth. Currently there’s no way that will happen with the robot getting stuck so easily.

Here is a video example on the robot becoming stuck on a slight change in incline:
robloxapp-20210102-1320342.wmv (2.3 MB)

Any suggestions?

My pathfinding script located within the robot and is:

local PathfindingService = game:GetService("PathfindingService")

-- Variables for the Model, its humanoid, and destination
local modelA = script.Parent

local humanoid = modelA.Humanoid
local destination = game.Workspace.PinkFlag
local pathParams = {
	AgentRadius = 6,
	AgentHeight = 5,
	AgentCanJump = true
}

-- Create the path object
local path = PathfindingService:CreatePath(pathParams)

-- Variables to store waypoints table and ModelA's current waypoint
local waypoints
local currentWaypointIndex

local function followPath(destinationObject)
	print("Starting followPath fuction")
	-- Compute and check the path
	path:ComputeAsync(modelA.HumanoidRootPart.Position, destinationObject.PrimaryPart.Position)
	-- Empty waypoints table after each new path computation
	waypoints = {}

	if path.Status == Enum.PathStatus.Success then
		print("path.status was a success")
		-- Get the path waypoints and start zombie walking
		waypoints = path:GetWaypoints()
		-- Move to first waypoint
		currentWaypointIndex = 1
		humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
	else
		-- Error (path not found); stop humanoid
		print("path.status had an error")
		humanoid:MoveTo(modelA.HumanoidRootPart.Position)
	end
end

local function onWaypointReached(reached)
	if reached and currentWaypointIndex < #waypoints then
		currentWaypointIndex = currentWaypointIndex + 1
		humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
	end
end

local function onPathBlocked(blockedWaypointIndex)
	-- Check if the obstacle is further down the path
	if blockedWaypointIndex > currentWaypointIndex then
		-- Call function to re-compute the path
		followPath(destination)
	end
end

-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)

-- Connect 'MoveToFinished' event to the 'onWaypointReached' function
humanoid.MoveToFinished:Connect(onWaypointReached)

followPath(destination)
3 Likes

Hey!

Maybe this can help:

So try casting a ray and see whether NPC can really see the checkpoint. Maybe make a simple :MoveTo() sequence, for example according to your case, first move the robot straight (this should already enable finding the path again, read more in the appended post). If this doesn’t work, move either left or right and so on.

By the way, this looks like a really cool robot! I like it and hope it works. If it doesn’t, please notify me, so we can search further for working solutions.