I have a train, I have tracks. But no matter what I do, it keeps derailing. The only way I keep it stable on the track is if it’s going incredibly slow.
Like I picture a rollercoaster, I want it to be able to fly along the tracks and never have to have any concern of derailment Train Derail.rbxl (64.6 KB)
I’m not sure what physics I could change, I’ve messed with making gliders have different friction and densities/etc. I tried placing gliders underneath the rail too (so double gliders) and they still somehow phase through track colliders.
But it’s just constant, no matter what I do, the train always finds a way to derail
What you just observed is often referred to as tunneling, it’s where object moves fast enough that there is enough gap between physics steps that it can just hop from one side of the object to another, essentially never touching it in the process.
I was able to trigger 240 hz by switching from adaptive to fixed physics stepping method, which stopped the train from derailing on the first turn, but even that wasn’t enough for the second turn.
The Solution
Most video game engines provide something called continuous collision detection (CCD), which is more computationally expensive but does solve the problem for most cases. As for Roblox, there doesn’t seem to be any implementation of CCD, and if there is, it isn’t directly accessible to the developers, so you are left with few alternatives:
A) Lower the speed of the train.
B) Make the walls thicker.
C) Script the train movement yourself rather than relying on Roblox’s physics engine.
D) File a feature request requesting an option to utilize more accurate collisions.
If you are going with either A or B, I would recommend switching the physics stepping method to Enum.PhysicsSteppingMethod.Fixed (“Fixed”) due to the nature of your game (it heavily relies on the physics engine).
If you wonder how I managed to take the screenshots, it was possible with the physics controls that were added last year: Pausing Physics in Studio [Beta].
I stopped relying on velocity physics with trains years ago, Roblox’s physics engine is way too buggy for it. Most big train games use a nodal approach because trains derail way too easily in the Roblox engine. Some Airport People Movers already had to do loads of hacky stuff with the bogies.
If you need physics, you can probably use a combination of AlignPosition and AlignOrientation to force it to a CFrame physically.
This is very informative! Thank you for going into so much detail, a lot of this stuff I was not aware of! Will try out these few things and get back when I’ve tested
My concern with using a nodal approach was attaching players to the moving train? How would I go about that effectively? Like in terms of if I was to say use tween or lerp to nodes. Cause I have 2 bogies, I’d needa do each one separately, so train can turn effectively on corners and not look stiff
You mention PivotTo being bad in one of your responses, why is that? I don’t want to use tween, as I want this all server sided, but want the train to still feel as smooth as it would with physics
PivotTo() is made to move every part of a model together, but the engine is not optimized for that
The engine is optimized at moving welded assemblies, the cost of moving the rootpart only (which also moves every welded part) is far lower than moving every part on their own (which is equivalent to PivotTo(), on an unwelded model)
Note that you have to move the rootpart using .CFrame for the welded parts to move along it, .Position behaves differently for god knows what reason
You can also use TweenService on the rootpart of the welded assembly, it works perfectly. How I made it smooth is by updating the CFrame every frame