Hello,
I have a traffic system which is basically the server saying to all the clients which car (MeshPart) to spawn with info (Model, Lane, Speed, Waypoint[i] and Waypoint[i+1]).
For optimization, cars outside a certain radius are removed. When a car re-enters the player’s radius it needs to resume its tween from its current position → next waypoint, instead of restarting from Waypoint A → Waypoint B.
It works fine, but when I tried to add curves it started being a bit weird.
The car’s speed seems to slow down during the curve and then go back to normal once it’s done.
This is the tweening function, in short:
function playTween(car, part, tweenTime, trafficSpeed)
coroutine.wrap(function()
local distance = (car.Position - part["Part"..i+1].Position).Magnitude
local tweenTime = distance / trafficSpeed
local TweenInfos = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut,
0,
false,
0
)
local finalCFrame = nextPartCFrame * heightCFrame
local nextPart = part["Part"..i]
local currentPos = car.Position
local targetOrientation = nextPart.Orientation
local rotatedCFrame = CFrame.new(currentPos) * CFrame.Angles(
math.rad(targetOrientation.X),
math.rad(targetOrientation.Y),
math.rad(targetOrientation.Z)
)
car.CFrame = rotatedCFrame
local MainTween = TweenService:Create(car, TweenInfos, {CFrame = finalCFrame})
MainTween:Play()
MainTween.Completed:Wait()
end)()
end
Are the distances too short and Roblox cannot calculate such a fast time for the tween?
Thanks
