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)