Hello everyone,
Recently I was making a multi-car automatic train System using physics. However, as the majority considers, the train derails frequently in the server environment. I have recently been notified that the train can be moved through CFrame system, however this require node blocks.
My railway is somehow both automatic and manual at the same time and my concern is that the huge amount of node blocks might hinder the smoothness of the game.
Is there a method which the CFrame train system may work without node blocks, but merely detecting tracks to operate turns?
Well, recently I found a way to try making CFrame train system with node blocks. Here is my script reference for the CFrame system, but the train moves apart once turning starts. (As follows)
local Support_Glide = script.Parent.Parent.BaseSupport
function Sum(Given)
local Summation = 0
for i,b in pairs(Given) do
Summation += b
end
return Summation
end
game["Run Service"].Heartbeat:Connect(function(dt)
print(dt)
local V_lower = dt*script.Parent.TrainSpeed.Value
local NumRails = 0
local YOrienations = {}
print(script.Parent.Parent.TrackDetector:GetTouchingParts())
for i,b in pairs(script.Parent.Parent.TrackDetector:GetTouchingParts()) do
if b.Name == "RailEdges" then
NumRails += 1
local BlockOrY = b.Orientation.Y
if BlockOrY < -90 then
BlockOrY = BlockOrY + 180
elseif BlockOrY > 90 then
BlockOrY = 180 - BlockOrY
end
YOrienations[#YOrienations + 1] = BlockOrY
end
end
print(NumRails)
local AvgY = Sum(YOrienations)/#YOrienations
local NewOrientation = AvgY - script.Parent.Orientation.Y
-- local CalibrateMid =
script.Parent.CFrame *= CFrame.new(V_lower,0,0) * CFrame.Angles(0,math.rad(NewOrientation*dt) or 0,0) * CFrame.new(0,0,(V_lower^2)*dt*math.rad(NewOrientation*dt))
end)
Is there a way to solve this?
Thank you🙏