How would I make a TweenService car steer realistically?

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?

2 Likes

idk how to do it but try using EasingStyle as Linear

It’s not the EasingStyle that is the problem. EasingStyle is just how the tween looks like. Linear means it’s abrupt, while Sine gives you a smoother takeoff or stop in this case.

im just saying because i made a cart system using tweens and i put EasingStyle as Linear and i got perfect results
even when the cart does 90 degree turn it moves as expected so its worth a try to use Linear

I don’t think you can tween the path in a curve, unless you create multiple tweens. You should probably just use a loop and set the CFrame around the center of curvature for the turn

Could you please set that up for me? I mean you don’t have to, but I’d greatly appreciate if you did so. I don’t have much free time.

for i = 1, 90 do
    car.CFrame = center.CFrame * CFrame.Angles(0, 0, math.rad(i)) * CFrame.new(10, 0, 0))
    wait()
end

something like that, tweak the numbers a bit and you should get what you want

It steers in a completely different direction. No matter how I edit the numbers, I can’t get it to steer properly. It just steers upwards or downwards, not sideways.

You can’t tweenservice curves. Tweenservice is only used in linear paths. To make a curved path you need to use bezier curves and multiply it with an alpha. You need to iterate it until the alpha is 1 if you want a curve.