Car Drives Through A Wall

Hi all,

I’m experimenting with Pathfinding x NPC Vehicles. I’ve placed two wall obstacles and a goal part and I’m trying to make a self-driving car that would go around the walls and touch the goal part. However, my vehicle seems to get stuck on the obstacles as if they were not here in the first place.

Here’s an excerpt of my code (Only the relevant parts):

local Pathfinding = game:GetService("PathfindingService")
local RunService = game:GetService("RunService")

local waypoints

Goal1 = workspace:WaitForChild("Goal")
CarRoot = Car.Body.FrontVector

local path = Pathfinding:CreatePath({
	--AgentHeight = 6.5,
	AgentRadius = 12.5,
	--AgentCanJump = false,
	--AgentCanClimb = false,
})

function followPath(destination)
	
	local WP_Pos = Vector3.new(destination.Position.X, CarRoot.Position.Y, destination.Position.Z)
	local success, errormessage = pcall(function()
		path:ComputeAsync(CarRoot.Position, WP_Pos)
	end)

	if success and path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		for _, WayPoint in ipairs(waypoints) do
			repeat
				if checkSight(Goal1) == true then
					break
				end
				setSpeed(55)
				driveTo(WayPoint)
				task.wait()
			until (CarRoot.Position - WayPoint.Position).magnitude > 10
		end
	else
		warn("Path not Computed!", errormessage)
		setSpeed(0)
	end
end

setSpeed(0)

while task.wait() do
	if checkSight(Goal1) == false then
		followPath(Goal1)
	else
		driveTo(Goal1)
	end
end

Even though I’m using AgentRadius my vehicle is still running towards walls. How exactly can I solve this issue?

Thanks in advance!

I’ve changed it to < 10 and the issue persists.

1 Like

Kind of a stupid solution, but make the wall wider.

Why? Roblox’ pathfinding has a system that checks if the path is blocked. It does this in cells I believe. The wall might not be big enough for the system to understand that it is blocking the way. The wall might intersect a cell by 40%, which will not register as blocked. This system is prone to errors like these where it finds false negatives (cases where the path is blocked, but is not actually registered as such).

Small objects tend to mess with the pathfinding, so you should try to avoid that as much as possible.

1 Like

I made a mistake in this function. The issue was not in the code I shared

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.