Car AI Steering Problem

I tried making a Car AI using this video

But instead of using the chassis he made I used the one that Roblox made:
image
image

AI Script:

local Chassis = script.Parent
local Target = Chassis:WaitForChild("Target")
local Constraints = Chassis:WaitForChild("Constraints")
local Guide = Chassis:WaitForChild("Guide")
local RunService = game:GetService("RunService")

local Steer = 0
local Throttle = 0

RunService.Stepped:Connect(function()
	local CF = Guide.CFrame
	local Converted = CF:PointToObjectSpace(Target.Position)
	
	for _, Constraint in next, Constraints:GetChildren() do
		if Constraint:IsA("CylindricalConstraint") then
			Constraint.AngularVelocity = Throttle
		end
	end
	
	for _, Constraint in next, Constraints:GetChildren() do
		if Constraint.Name == "SteeringPrismatic" then
			Constraint.TargetPosition = math.clamp(Steer, -1, 1)
		end
	end
	Steer = Converted.X
	Throttle = Converted.Z
end)

The Problem is that it doesn’t Steer straight it just goes left and right while going to the target:
robloxapp-20220902-1219175.wmv (3.7 MB)

1 Like

Try using the car that the video is designed to see if it works. If it does, then you’ll need to change some code (or the car) to support the new car you have.

I kinda want to apply it to the roblox car instead of the chassis in the video…

The only problem is that it doesn’t steer right

Yes, we get that, but maybe they aren’t set up the same.
Compare the car used in the video and the Roblox car to see how they are different.

What I’m trying to say is check if this is either a scripting problem or a building problem. See if you can make a replica of that car in the video and test if it works. If it does, then it’s an issue with how the car is setup and you maybe could find better results in building support

Is the AI actual AI? If so, it will need to learn first. Like the 2nd post by @ChickHenEn said, you should try it with the provided chassis to test it first, to be sure you don’t waste your time and actually see how it works, and it will also help you understand how to make it work with the Roblox chassis.

It’s a scripting problem…

The problem is the steering in the script.

for _, Constraint in next, Constraints:GetChildren() do
		if Constraint.Name == "SteeringPrismatic" then
			Constraint.TargetPosition = math.clamp(Steer, -1, 1)
		end
	end

As shown here in the video, the car doesn’t really go straight:
robloxapp-20220902-1219175.wmv (3.7 MB)

You keep stating that the car you use isn’t doing the same thing as the car in the video. The script may work just fine, but not with the model YOU are using.

So how is the SteeringPrismatic different from the Roblox car compared to the one in the video.

The problem you are having is like saying ‘I tried to make bread using a recipe, but I changed one of the ingredients and it didn’t come out right’. You can’t blame the recipe if the ingredients are different.

I thought steering used TargetAngle. Also, I don’t think that’s the steering. I thought the steering was a hinge.

Nope the chassis on the video uses a Hinge Constraint, but for the chassis that roblox made uses a Prismatic Constraint

I thought that was for suspension. You should double check your constraints.

In the video the Hinge Constraint ActuatorType is Servo but for the roblox chassis the ActuatorType is None.

if you change the SteeringPrismatic TargetPosition to -1 or 1 it steers to the left or righy

I must be confused. The angle should be used, and it should be 40-60 degrees. It shouldn’t be a value from 0-1.

(and to @SubtotalAnt8185 's post)

In the video is the PrismaticConstraint attached to parts that steer the wheel hinges, like a real car?
I’ve used that setup for my cars before.

It works like the VehicleSeat if the value of the Steer is -1 then it turns to the right and if the value is 1 it turns to the left

Left:
image

Right:

Sorry for taking so long

I’ve Fixed It Using Raycast Thanks For Trying To Help!

2 Likes