I have an AI car using TweenService. Technically, it all works, but at the moment when the car turns right, it just tweens directly to it, cutting through the grass instead of staying on the road. If the video doesn’t work, just download it and watch it on your device.
What I’d like to achieve is it realistically steering around the edge of the road.
Here’s the block of code in question.
elseif script.Parent.Going.Value == "Right" then
local waypoint = Instance.new("Part")
waypoint.Name = "Turn"
waypoint.Shape = "Block"
waypoint.Material = "Plastic"
waypoint.Size = Vector3.new(9.4, 8.2, 2)
waypoint.Position = workspace.Placeholders.EastTurn.Position
waypoint.Orientation = workspace.Placeholders.EastTurn.Orientation
waypoint.Anchored = true
waypoint.CanCollide = false
waypoint.Transparency = 1
waypoint.Parent = script.Parent.Points
local waypoint = Instance.new("Part")
waypoint.Name = "End"
waypoint.Shape = "Block"
waypoint.Material = "Plastic"
waypoint.Size = Vector3.new(9.4, 8.2, 2)
waypoint.Position = workspace.Placeholders.EastEnd.Position
waypoint.Orientation = workspace.Placeholders.EastEnd.Orientation
waypoint.Anchored = true
waypoint.CanCollide = false
waypoint.Transparency = 1
waypoint.Parent = script.Parent.Points
local Turn = {}
Turn.Position = script.Parent.Points:WaitForChild("Turn").Position
Turn.Orientation = script.Parent.Points:WaitForChild("Turn").Orientation
local End = {}
End.Position = script.Parent.Points:WaitForChild("End").Position
End.Orientation = script.Parent.Points:WaitForChild("End").Orientation
local tweenInfo = TweenInfo.new(
3, -- Time
Enum.EasingStyle.Sine, -- EasingStyle
Enum.EasingDirection.In, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tweenInfo2 = TweenInfo.new(
15, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.In, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = tweenService:Create(script.Parent,tweenInfo,Turn)
tween:Play()
tween.Completed:Wait()
local tween2 = tweenService:Create(script.Parent,tweenInfo2,End)
tween2:Play()
tween2.Completed:Wait()
script.Parent:Destroy()
end
end
Can someone please change this so that it works as I described above?