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!