In the project I am working on, there is a track system on which cars are free to move. The direction of the car should be aligned with the track at all times, and the probability of derailing should be as low as possible. Additionally, the cars are unaffected by gravity, but other external forces like pushes should move the cart along the track.
Problem
Figuring out how to properly build the track and car is proving to be a challenge for me. I cannot use the AlignPosition or CFrame objects because the car is not moving at a set speed and can be affected by other forces.
I opted to make a 4-wheeled, invisible proxy slider move along the track using guide rails on the top and bottom to keep it from derailing, but the slider jitters (especially on the curves, which increment at 3 degrees) which makes the car on top wiggle uncontrollably and eventually fling off. The design of the slider is as follows:
A single root part in the center to which four wheels are attached with HingeConstraint objects.
A pair of WeldConstraint objects linking the two front wheels together and the two back wheels together.
A WeldConstraint linking the base of the actual car to the root of the proxy slider.
The following clip demonstrates the issue I am having with this approach:
I made the root of the slider non-collideable, and the four wheels and guide rails all have 0 friction, an elasticity of 1, and an elasticity weight of 100.
Other Solutions
I thought about using a series of PrismaticConstraint objects, but that probably would not work out well considering that the cars can be autonomous or player-controlled. (This means when the server is controlling the car, it would have to know exactly when to switch from one PrismaticConstraint to the next which would be difficult for cars moving at a significant speed.)
I hate to say this, but your best bet is using CFrame, and manually putting waits to “simulate” physics, or tweening slowly on up hill climbs, and fast going down. Good luck!
Try to build a more sophisticated chasis that surrounds the entire track. In my experience, you also want to make sure there is some small amount of space between the spheres and the track. This is to allow for turning and inclines. Good luck!
From the video, I can tell that your car stopped moving at the beginning of the curvy track. Just to add @cpc20514’s statement right there, you might want to extend the weld constraint limit to let the wheels run on a curvy track, which would require slightly more space.
It might work better with physics if you make it look more like the following image. Obviously, you can see this type of chassis allows the car on top to be locked on the rail with a very small chance of derailing. But with your system, I don’t think this would be necessary anyway since you have a single root part that attaches all of the coaster car parts together.
Try making the distance between the two back wheels a bit larger or allow some change in distance/angle between front and back wheels? Because of the slight change of degree, the cross-section of the rail the wheels have to pass by is slightly larger than the gap between the wheels.
I redesigned the chassis, and it can travel around the track smoothly when the car is not attached. When the car is attached, it wobbles and shakes frequently (but can still go around the track). I tried making the car massless, but that did not seem to change anything. I will try and experiment more to try and fix the issue, thanks for your help so far.
Not sure if this is useful to you, but have you thought about using TweenService to simulate coaster physics? I am working on a zipline system that is similar and uses Tweens (see below). It utilizes a system of parts (named Guide1, Guide2, Guide3… etc.) to guide the trolley along the line.
Disclaimer: I have not made a coaster myself on Roblox. However, that being said, I think writing your own physics and using CFrame is the way to go if you’re willing to put the extra effort into learning and creating it
+Much lower computational load on the server
+Gives you more control over the physics and behavior
+Completely reliable, the train can’t randomly derail or get stuck or glitch out.
+Smoother, the train wont bounce between the rails, and no issues with physics ownership
+Wont break when Roblox makes changes to the physics engine
-A lot more effort
-A lot harder to add spinning or other varieties in than when using physics
The actual calculations for a basic chain lift coaster should be quite simple, as you only really need to consider the forces of gravity pulling the train along or back the track, and drag.
You would have to move the train locally for each client using CFrame. You should use RunService.RenderStepped as the timer for updating it, the event will pass the time since last frame as it’s first parameter which you can use in the calculations.
The hardest part for me is making correctly follow the path of the track, as it’s not something I’ve done before (I’ve only used straight tracks)
Perhaps a 5th invisible ball in the underside of a u-shape attached rigidly to the center of the main part would help with that?
Obviously would need to be slightly smaller than the gap, but might help stabilize it? Just in general try to experiment with different configurations to see what works the best.
I tried redesigning the track, but the wobbling of the chassis is still there. It is actually not much at all, but it is very noticeable on the cars since they are much larger.
I created another track and set of cars that use TweenService and custom CFrame physics as others have suggested. I have not found a way to replicate forces, but that is not too much of a big deal. The main problem now is that I realized connecting multiple cars together is not as easy as I had previously hoped.
I tried two methods of linking cars together. In the first, a single head node is moved along the track while the first car follows it. Subsequent cars also have a set of nodes, but those are calculated in a Heartbeat function based on the current position of the head node. Unfortunately, when the head car is curving, the rest of the cars that follow have snappy movements. All cars are rigidly attached to their nodes. (I tried altering the AlignOrientation to be non-rigid, but it creates a wobbling effect.)
The second approach involves all nodes using TweenService, but even when I play all the tween objects at the same time, cars end up lagging a bit behind each other.
Edit: I made all cars use non-rigid alignment objects with low responsiveness and high force, and it seems to be working well. I would have preferred to use another method, but this is manageable for my project.