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?