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:
Thanks For Any Help!