We're Trying To Make A Car AI System. Any Ideas?

What do you want to achieve?
My friend and I are trying to make a car AI for our game. We want it to be able to get through a track to the finish line, while still working if it gets bumped by another car.

What is the issue?
We haven’t found many good solutions or tutorials on how to do this, or at least something similar. The current solution I’m testing is using PathFinding on the car. I thought of using PathFinding in conjunction with the car’s DriveSeat values (Throttle, Steer, etc.) but haven’t found any way to to that.

What solutions have you tried so far?
We’ve tried doing PathFinding, directly affecting the DriveSeat through a script and “Touched:Connect” functions, and looking into other methods to no avail.

So far we’ve seen that the best, and most “true AI” way would be to create a Neural Network with Raycasting, and going through all that. The thing is, it would take a long time to do, and it’s something that isn’t really touched on at all in tutorials and resources. It would likely take months, or even years from what we understand.

PathFinding seems like a more viable and time-saving option for us, that is, if we can get it to work. It wouldn’t take too long to do, depending on what we can find out, and we don’t have to go through learning Neural Networks in depth and all.

So far I’ve managed to make a simple car move with pathfinding, just by moving it’s position in jerks of movement (see GIF & Script below).

What I’m trying to find out is this:

  • What options would we have in accomplishing this?
  • What would be the most viable option in your opinion?
  • How would we do this, in simple terms?
  • Is there a way to make the PathFinding work in conjuction with the DriveSeat?

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
	wait(.2)
	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

GIF:
PathFindingCar1
Thanks For Any Help!

2 Likes

What i would do is definitely not the right way to do it, but I would hard code paths for each individual AI car and then program them to follow those paths to the best of their ability

1 Like

The best way to do it would be to use network. Unfortunately, when something is as complex as a vehicle AI system, it is extremely hard to do without using a trainable neural network.

Here is a module that was published recently by @Kironte that makes the whole process of creating and training a neural network much easier:

I’m assuming your race track is quite complex, so there are not too many other solutions other than using machine learning in some way.

The only other idea I can think of is to have many different checkpoints on your race track that your vehicle’s are always trying to drive to. Then your cars will always have a defined point to make as a target at all times.

Hope you guys can figure out a solution that works well! :smile:

2 Likes