Whats the best path-to-target system (except for pathfindingservice) for Police Cars and criminal cars

So in my car system, it steers to the target to ObjectValue thats called Target.
And, somehow its not even successful as it looks.
All it does just follows directly without making a current path, Now however this can be solved by using PathfindingService, but the problem its not for vehicles. PathfindingService is only for Humanoids,
Non otherless i tried pathfinding and it worked well until one of the cars get stuck and somehow when you go a little far away from them, they stop pathfinding.
Streetracers need for to avoid danger and objects, and Police need for to navigate the Streetracer’s position and get to them.

Obviously A* Algorithm, Neural Network are the only one to fix it, but they’re too hard and complicated to get with, and i don’t even understand.

Like whats the easiest and best system i can do?
I can’t find other nonotherless, im not a advanced scripter.

Some link helped me a little bit, but not with the path-to-target situation:

1 Like

I’ve found that PathfindingService seems to work okay for vehicles with the correct implementation, you can try it out with the click to walk movement control setting (in the menu), but I have also made a module that would calculate steering and throttle using pathfinding.

local service = {}

local PathFindingService = game:GetService("PathfindingService")
local cancel = false

function service:Cancel()
	cancel = true
end

function seatMove(humanoid, dir, root)
	humanoid.SeatPart.ThrottleFloat = dir:Dot(root.CFrame.LookVector)
	humanoid.SeatPart.SteerFloat = dir:Dot(root.CFrame.RightVector) * humanoid.SeatPart.ThrottleFloat / 25
end

function service:MoveTo(target, maxWaypoints, mindist, vehicleMinDist)
	mindist = mindist or 5
	vehicleMinDist = vehicleMinDist or 20
	
	local humanoid = script.Parent.Humanoid
	local root = humanoid.RootPart
	
	local isVehicle = humanoid.SeatPart and humanoid.SeatPart:IsA("VehicleSeat")
	
	local path = PathFindingService:CreatePath({
		AgentRadius = (isVehicle and 5) or 3,
		WaypointSpacing = math.huge,
		Costs = {
			Water = 20,
			Neon = math.huge,
			Grass = 10,
			Concrete = 5
		}
	})
	
	
	path:ComputeAsync(root.Position, target)
	
	if path.Status ~= Enum.PathStatus.Success or (target - root.Position).Magnitude < 5 then
		--warn(path.Status)
		humanoid:MoveTo(target)
		if isVehicle then
			seatMove(humanoid, target - root.Position, root)
		end
		return
	end
	
	local waypoints = path:GetWaypoints()
	
	for i, waypoint in pairs(waypoints) do
		if cancel then cancel = false break end
		if maxWaypoints and i > maxWaypoints then break end
		
		
		local targetPosition = waypoint.Position
		
		--[[local visual = Instance.new("Part") do
			visual.Shape = Enum.PartType.Ball
			visual.Anchored = true
			visual.Material = Enum.Material.Neon
			visual.Position = targetPosition
			visual.CanCollide = false
			visual.CanTouch = false
			visual.CanQuery = false
			visual.Size = Vector3.new(1, 1, 1)
			visual.Parent = workspace.CurrentCamera
			task.delay(15, visual.Destroy, visual)
		end]]
		
		while ((targetPosition - root.Position) * Vector3.new(1, 0, 1)).Magnitude > mindist do
			local dir = targetPosition - root.Position
			humanoid:MoveTo(targetPosition)
			if isVehicle and humanoid.SeatPart then
				if (dir * Vector3.new(1,0,1)).Magnitude < vehicleMinDist then break end
				seatMove(humanoid, dir, root)
				if root.AssemblyLinearVelocity.Magnitude < 1 then
					humanoid.SeatPart.ThrottleFloat = math.random(-1,1)
					humanoid.SeatPart.SteerFloat = math.random(-1,1)
					break
				end
				if root.AssemblyLinearVelocity.Magnitude > dir.Magnitude and humanoid.SeatPart.Steer ~= 0 then
					humanoid.SeatPart.ThrottleFloat = -humanoid.SeatPart.ThrottleFloat
				end
				task.wait()
			else
				humanoid.Jump = waypoint.Action == Enum.PathWaypointAction.Jump
				task.wait(.1)
			end
		end
	end
	if isVehicle then
		humanoid.SeatPart.Throttle = 0
	end
	humanoid:Move(Vector3.new())
end

return service

I’m planning to upload this to community resources later today but with more documentation, but you just need to know how pathfinding works to be able to understand how this works.

Anyways, it works pretty well with the legacy car system, but I have used it with LegacyCarConverter and it works really well there but does not work with stuff like A-Chassis unless you perform some intense modification to them.

3 Likes

Hi, ill like to respond that my car system works without a driver, so it does steer and throttle without because its runned by a repeating script that if throttle then do velocity and something like that, i just need a best path to target system, my car npc system is good, but it needs one big piece and its path-to-target

I mentioned the script snippet earlier in my post that changes these values using PathfindingService.