Project with an example of scripts work:
roller coaster test.rbxl (40.6 KB)
script v1
-- With time, the model will stop touching the part and will go to infinity
local qtween = game:GetService("TweenService")
local info = TweenInfo.new(
0.12, -- Time to make a smooth turn
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut
)
local mod = workspace.Model
-- box colision
local ovr = OverlapParams.new()
ovr.MaxParts = 1
ovr.CollisionGroup = "no"
local col = mod.Colision
local CFrame_col
local size_col = col.Size
local box,box1 -- list
local xr,yr,zr
local CF= Instance.new("CFrameValue")
CF.Value = mod.WorldPivot.Rotation
task.wait(4)
function start() -- The object moves without stopping
while task.wait() do
mod:PivotTo(mod.WorldPivot*CFrame.new(0.3,0,0))
end
end
task.spawn(start)
while true do
task.wait()
CFrame_col = col.CFrame
box = workspace:GetPartBoundsInBox(CFrame_col,size_col,ovr)
-- A list is created with 1 object, which is the next part. To read the rotation and apply it to the model
if #box == 1 then
box[1].CollisionGroupId = 1
-- New collision group for the part, so it no longer appears in the list
local q = box[1]
task.delay(1,function () q.CollisionGroupId = 0 end)
-- Returns the original collision group, so you can move the model in circles
xr = math.rad(box[1].Rotation.X)
yr = math.rad(box[1].Rotation.Y)
zr = math.rad(box[1].Rotation.Z)
-- Since "CFrame.Angles" only has "(number,number,number)" for convenience, I create three variables
-- in "CFrame.Angles" you cannot put "box[1].CFrame.Rotation", I tried
-- a not working code example: CFrame.Angles(box[1].CFrame.Rotation)
CF.Changed:Connect(function(F) -- Triggers as soon as "CF" value changes, "F" = "CF.Value"
mod:PivotTo(CFrame.new(mod.WorldPivot.Position)*F) -- Turning without changing position
end)
local tween = qtween:Create(CF,info,{Value = CFrame.Angles(xr,yr,zr)})
tween:Play()
end
end
script v2
local mod = workspace.Model_V2
local qtween = game:GetService("TweenService")
local info = TweenInfo.new(
1, -- Time for moving and turning at the same time
Enum.EasingStyle.Linear,
Enum.EasingDirection.In
)
-- box colision
local ovr = OverlapParams.new()
ovr.MaxParts = 1
ovr.CollisionGroup = "no"
local col = mod.Center
local CFrame_col
local size_col = col.Size
local box -- list
local CF= Instance.new("CFrameValue")
CF.Value = mod.Center.CFrame
task.wait(4)
while true do
task.wait()
CFrame_col = col.CFrame
box = workspace:GetPartBoundsInBox(CFrame_col,size_col,ovr)
if #box == 1 then
box[1].CollisionGroupId = 1
local q = box[1]
task.delay(1.1,function () q.CollisionGroupId = 0 end)
CF.Changed:Connect(function(F)
mod:PivotTo(F)
end)
tween = qtween:Create(CF, info, {Value = box[1].CFrame*CFrame.new(3,0,0)})
tween:Play()
end
end
I am not going to insert a bunch of example videos here so that the topic does not take 100 km, just open the project and you will see everything I describe below
I’m new to scripting, in fact I’ve been learning roblox since 03/18/2022, I haven’t spent all my time learning scripting, I’ve been partially creating objects, and before I decided to do this roller coaster, I was doing great.
Here’s what I have:
In v1 the model moves only with CFrame, I couldn’t figure out how to make a smooth rotation, I just connected TweenService.
Problems (something I’ve been trying to fix, but haven’t figured out how)
-
the object does not go to a point as in v2, but simply moves forward all the time, and when it touches a new part, repeats a turn, seems like an ideal system, but over time, the object due to inaccuracy of rotation (During the turn the object is moving, and before the turn is completed, the model has time to move slightly away from the original desired position), will get out of line and just fly away to infinity.
-
as in v2, there is no speed control, but I think this problem is clearly easier to solve than previous one
-
I don’t really understand how it works, but the character won’t move with the object, because there’s no physics, and everything moves through the CFrame.
In v2, the model moves with the TweenService, CFrame only for the calculated points where to move.
Problems
-
When rotating the model shifts a bit, the solution would probably be to create more intermediate points, or to reduce the size of the part
-
Unlike v1, I can’t even imagine how to control the speed here, look like you can’t change it here. + all parts must be the same size (and at the same distance) otherwise the speed will constantly change (longer = faster, shorter = slower)
-
is the same as 3 in v1.
I think v1 is better than v2, even though it is more complicated, because if I solve the first problem, speed control will not be an issue (do a smooth increase/decrease)
And so, I have a request, who really knows, tell me how to solve the first problem in v1, or maybe better to use v2? Or somehow combine these two versions to make v3, where everything will work very well. I dug a lot of information, thought for a long time, what and how you can do, but realized that it is not in my power, so I turn to connoisseurs.
I am not interested in moving slides by setting the speed (using the physical engine roblox) because there is a chance that the cars will just fly off the slide. After that they need to be restarted, and other problems, those who are good at it know what I mean. That’s why I decided to try to do a roller coaster through CFrame, I didn’t think it would be that difficult.
I saw how to creation Frame+physics, but I do not even know how to do it (I tried to do it, but it did not work)