You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to make my “Endorsed” cars move properly towards the target.
-
What is the issue?
The issue is, The AI keeps going left and right and circling around the target. -
What solutions have you tried so far?
I tried to use math.rad(Targetposition) to make it much smoother, The wobbling is gone but the AI is still circling around the target due to the steering not being that sharp.
Note: The script I took is from a resource that chris linked into his AI pursuit post. I took it and modified it a little bit by changing the chassis and angle.
local police car = workspace["Police Car"]
--ignore
local Constraints = script.Parent.Constraints
MotorFL = Constraints.MotorFL
MotorFR = Constraints.MotorFR
MotorRL = Constraints.MotorRL
MotorRR = Constraints.MotorRR
SteeringPrismatic = Constraints.SteeringPrismatic
Goal = workspace.FigureAI.HumanoidRootPart
FrontVector = script.Parent.Body.F_bumper
--The one who moves the vehicle
MotorFL.AngularVelocity = 50
MotorFR.AngularVelocity = 50
MotorRL.AngularVelocity = 50
MotorRR.AngularVelocity = 50
SteeringPrismatic.TargetPosition = 0
game:GetService("RunService").Heartbeat:Connect(function()
local PositionDifference = (Goal.Position- FrontVector.Position).Unit
local GoalFrontVector = FrontVector.CFrame.LookVector
local DotProduct = PositionDifference:Dot(GoalFrontVector)
local Angle = DotProduct
local TargetPosition1 = math.deg(math.acos(Angle))
local TargetPosition = TargetPosition1 - 90
if TargetPosition < 90 then
TargetPosition = TargetPosition
end
if TargetPosition > 90 then
SteeringPrismatic = 1- TargetPosition
end
SteeringPrismatic.TargetPosition = TargetPosition/ 20