Implementing physics based spline/rail movement

I’m developing a game which features a rigidbody object that is able to attach itself onto rails that exist in the world, locking its position and travel onto the rail. Consider how the rollers shown below would travel along the path.

I know that the typical way most people do this is to interpolate a position along a path from the start to end, with the rotation of the object aligning with the rail.
Unfortunately, the exact use I have for this feature, this is not an option!
It’s vital that the object that I have attached to the rail, remains as a dynamic rigidbody. I cannot fake the movement of it.

The theory I’ve come up with on how I’d design the feature is like so: If I had a way to constrain the center of the body to always remain above the spline, as if it had a 0 length fixed joint connecting the two, that would stop the body from moving off the path.
Then if I could restrict the linear velocity so it is only able to point forwards, and then rotate the body so its angle always remains tangent to the curve, that should guarantee the body is only allowed to move precisely along the route of the spline.

How I’d actually achieve such a thing, I’m not quite sure. Personally, it doesn’t sound like this would be the most complicated thing to develop. Unfortunately the majority of results Ive found are people faking the movement by making the transform.position follow the curve, nobody seems to be doing a physically accurate version.

If I was to start to work on a feature like this, what would be a good approach?

Surely not the most complicated, but pretty high up there. It‘ll be easier to make a networked multiplayer game because you can work with established frameworks, concepts, best practices. Here, you need to experiment. A lot. And probably fake things heavily.

Physics ain‘t easy.
F = m*a is only that simple under the most ideal circumstances. There is also air resistance, friction, and a number of other things. And game physics only simulate unnaturally rigid bodies.

You really want to go ahead with this, make some simple test cases. A straight, a curve, a slope and a simple version of your vehicle. And a deep understanding on how game physics work, what its limitations are and how you can „fake it“. Then you could make some progress.

They know better. :slight_smile:

1 Like

Certainly nobody in the games industry would try this. There’s no point.

Games are always a Potemkin Village, not an actual “real thing.”

The components of any game have been carefully engineered to:

a) convey a particular impression of gameplay / context / reality

b) remain within CPU / GPU constraints

c) be easily develop-able by teams of generic developers with widely-varying skillsets