I’ve been working on a train/track system, which has been going very slowly and causing stress, but has nevertheless been quite a fun endeavour.
It works… sort of… but experiences a weird bug where the wheels start to twitch, eventually causing the train to bounce up and derail.
The engine consists of a static mesh (the main body of the engine) and a number of wheels, guides and constraints.
Each pair of wheels is parented to an axle, which is attached by physics constraint to a guide, (axle and guide are hidden in game) such that it can rotate about its axis freely, allowing the wheels to turn. The guide is constrained to the main body, such that it can swivel slightly around the z axis, allowing them to take corners easier, and such that it can slide slightly from side to side under the train, to help all wheels to stay on the rails as it takes the corner.
At the front and rear axle there is also a collision component which overlaps with the tracks (a spline mesh) and sets the location and rotation of the front and rear guide, to help guide the train. In fact the current set up of train and rails works even with this feature turned off, as the wheels are able to guide the train quite well by physics alone.
At the moment the wheels have a physics material that has 0 friction, so they don’t actually turn.
Propulsion is currently achieved by a physics thruster component placed between the middle wheels.
Here are some screenshots, taken from beneath the carriage, which shows the constraints of the guides and axles, and soon to follow will be a link to a youtube video (currently taking its time uploading!) of the train running on the track and experiencing the strange jumping bug, though not actually derailing itself. The bug presents itself even if the guides are fully constrained with no allowed movement, even if the wheels are prevented from rotating (they are frictionless) and with the train aligning itself by spline or not.
There are no bumps in the collision mesh for the track (in the video the visual mesh is identical to the collision mesh). The wheels are tapered towards the hub as on real rail wheels (try saying that 3 times fast!).
Can anyone offer any advice as to what could be causing this? I also noticed in earlier experiments that even with physics fully constrained, the components would sometimes rotate or slide about a little, is there anything I could be missing? I realise that these screenshots may not be enough, so I am happy to take more screenshots of anything anyone needs to see, or record further videos.
The above screenshot shows the undercarriage of the train. The cubes are the guides (or the axles, they are identical cubes in identical locations with all collision disabled).
The above screenshot shows the constraint settings between the rear guide cube and the main body. All other guide constraints are identical.
This final screenshot shows the constraint settings between the rear axle and rear guide. All other axle constraints are identical.
Finally, this video shows (from underneath the train) the engine running on a stretched s-shape track, including the weird wheel twitching bug. At the time of recording all constraints were locked except the axles rotating. The train doesn’t manage to jump free from the track, but you can see the problem cropping up, anyway.
[Edited to add video].