Traffic car turning calculation problem

I have a traffic script for a car I got from a free model. Basically it makes the car turn when the waypoint isn’t in front of the car

The car system I am using is the roblox one from the Racing Template and so it uses PrismaticConstraint which can go to max 1 and the code I am using has 90 for hinge constraint.

I tried for about 1 and a half hour and nothing.

    Goal1 = Car:FindFirstChild("Target").Value
	local PositionDifference = (Goal1 - FrontVector.Position).Unit
	
	local GoalFrontVector = FrontVector.CFrame.LookVector
	
	local DotProduct = PositionDifference:Dot(GoalFrontVector)
	
	local Angle = DotProduct
	
	local TargetAngle1 = math.deg(math.acos(Angle))
	
	local TargetAngle = TargetAngle1 - 90

can you show a video of the traffic vehicle not functioning?

You aren’t setting the PrismaticConstraint? What exactly is the Prismatic used for (suspension, steering, etc.)

Start by printing the variables like TartetAngle after you set them before you use them.

Are you setting the force of the steering high enough to get the wheels to turn?

Is the vehicle actually moving or steering at all?

Steering, I did print it and tried everything. The steering itself works but it always has the steering very sensitive as the steering is mostly about 10 when it should be like 0.1 or something. The problem is I don’t know how to make it be around -1 to 1. It’s hard to explain lol

Did you try math.rad instead of math.deg?

I don’t understand what you mean by the PrismaticConstraint has a max of 1?
If it’s got a 1 stud movement range you could try moving the Attachment further away from the steering hinge to decrease the angle.

The other thing if the angle is 10x what you’re expecting you can multiply the angle by 0.1 in your calculation.

1 Like

This line:

local TargetAngle = TargetAngle1 - 90

is the problem really, the other script works but I can’t make be 1 instead of 90

About the prismaticConstraint, it’s the car system, it uses that to move the tires.

obraz_2024-12-23_213615936
-89 is for the “TargetAngle” and the other is “TargetAngle1”.

I want for the -89 (which is the max) to be only one rather than 90

Also forgot to tell, math.rad works but it cannot go right as it cannot do the numbers in negative, neither diving works as it’s the same as with math.rad.

If you want a number range to calculate between 0 and 1 then divide by the number.

For example you want 90° to be represented as 1 then 90/90 = 1. That way if it’s halfway 45/90 = .5

Same as distances. Divide your actual distance by the max distance you expect it to be limited to.

You said the Prismatic moves the wheels, but that’s still a vague answer because it could still be suspension or steering related.
It really helps if you are really specific because people reading these posts might assume you mean one thing instead of what you actually mean. It’s better to say “The PrismaticConstraint steers the front wheels”. :grin:

If you want you can send me a stripped down model of the car here or by private message and I can have a look at it tonight.

1 Like

Nvm the problem was with the “FrontVector” part as it wasn’t really FRONT and I had to divide in another line than the “local TargetAngle”. Thanks for the help anyway lol