make a train follow tracks using physics

hello,

I am currently developing an Train Simulator and already got a train with tracks and such.
The train uses wheelcolliders for the wheels.
Now the problem is that the train drives of the track after while or drives directly off the track on non-straight parts.
Now i understand how a real train wheel works but i have trouble recreating that.
So my question is how do i make the train wheels stay on the track?
I think i need to add a larger piece/wheel to the wheel in the inside of the tracks but if that’s the case can someone then tell me how to do that?
I do want to use physics so path following is no option.

i hope someone can tell me.

Thanks

(from comments)

My mind kept asking myself questions, so I went and played with it.

What you need is a mesh collider. The entire 2-part wheel as a single mesh. You can optionally have a wheel collider on it as well to handle the wheel physics, but the wheel collider is essentially only 2 dimensional, it will only deal with collisions from outside in fore the ‘tread of the tire’, and will not react to collisions on the face. One challenge with a mesh collider is that you need a high number of faces to the wheel if you don’t already. The default Cylinder that I played with has too few faces, and each face on the edge was making it bump along and adds a lot of simulated friction of the wrong type.

But this worked. Here is the test scene i mocked up real quick: Dropbox - trainwheeltest.unitypackage - Simplify your life

I inverted the goal by having cubes as tracks and a few scaled cylinders as the parts of the wheels, and the style is backwards with the large part of the wheel outside the ‘track’ rather than inside. This is all for the sake of expediency and not having to model the various components first. I tilted the track so I could use gravity rather than having to apply power to the wheels. And I just rotated the cubes by 1 degree each to simulate a curve.

If I was going to turn this into a full solution, I’d have smooth curves, I’d properly weight the wheels and others to prevent them from ‘jumping’ from hitting the transitions too hard, etc… but i think this shows that it will work for you.

gamecreatorTim

Hello, wanted to know, if you found a solution to stabilize the wheels?