PathFinding Not Working With AI Car Test

So I’m trying to make a car AI that moves on a track for me and my friend’s game. I’ve came across some info on it, with multiple methods. Specifically PathFinding, Neural Networks, and using scripts to change the VehicleSeat’s values. At the moment I’ve been testing PathFinding, and using it with a simple car.

The problem is, when it moves to the object, instead of slowly rolling there, it instantaneously teleports directly to it. I want it to roll over to there using PathFinding.

And an extra question incase anyone might now about it: Is there a way to make an AI car move through a track? My idea was to take the VehicleSeat values such as Throttle/Steer, and use PathFinding to allow it to utilize it in a script, making the car move through the track. Now it seems that this won’t work. Any ideas?

About the main issue, here’s a screenshot of my Explorer, as well as the script.

ScreenShot:
image

Script:

wait(5)

local PathfindingService = game:GetService("PathfindingService")
 
-- Variables for the car and destination, etc.
local car = script.Parent.MainCar.Part
local carprimary = script.Parent
local humanoid = script.Parent.Humanoid
local destination = game.Workspace.DestinationTest
local throttle = script.Parent.MainCar.Part.VehicleSeat.Throttle
 
-- Create the path object
local path = PathfindingService:CreatePath()

-- Compute the path
path:ComputeAsync(carprimary.PrimaryPart.Position, destination.PrimaryPart.Position)

-- Get the path waypoints
local waypoints = path:GetWaypoints()

-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
	local part = Instance.new("Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.Size = Vector3.new(0.6, 0.6, 0.6)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace

	-- Move car to the next waypoint
	carprimary:MoveTo(waypoint.Position)
end

EDIT: Here’s A GIF as well
WayPointCar

Thanks for any help.

4 Likes

Each waypoint is spread out by a set distance. Additionally, you are iterating through the array without a wait, meaning it moves it to the next waypoint nearly instantaneously. This effectively makes it teleport. Add a wait() into the for loop and experiment with interpolation and other things to make it smoother (see Lerp).

1 Like

Ah I see. Quick question, would you happen to know of any way to have the car work with PathFinding and the DriveSeat values at the same time? Either way, thanks very for the solution!

1 Like

I’m not too sure. I’d have to look into it. I recommend doing research on it as there should be something out there on it.

Ah okay. Info on it is pretty scarce, and there are barely any, if any, complete guides showing how to make AI cars with a method like I mentioned above. Thanks though! Stay safe.