Different densities causing glitching with constraints

I have a train movement system which is controlled by the player. It depends on linear velocity to move with calculations made within the scripts based on the throttle input (W to increase throttle, S to decrease throttle, A to increase brake, D to decrease brake).

The train occasionally starts shaking when it’s stationary, however the actual bug begins when it starts moving. Upon increasing the throttle the train begins shaking a lot and in same instances it will fly off the rails.

After debugging I have noticed that the constraint I used to connect the two carriages together (Rod constraint) was causing the issue. Disabling the rod constraint appeared to make an improvement in terms of how much the train shaked. I also learnt that changing the densities on different parts of the train effected this issue.

Train shaking on the track with the rod constraint enabled:


Train shaking on the track with the rod constraint disabled: (Some shaking is visible but it isn’t that bad, and I would not use this as my solution because I need a way to connect the two carriages together)

Debugging methods I used and results:

  • The train was 30k studs away from 0,0,0 because of map size so I tested the behaviour of the train near 0,0,0 and it did not make a difference
  • Disabling the rod constraint, this led to the train not shaking as much but it showed some shaking with the bogies/axels and the shaking was worse on curves.
  • Deleting any visual models and leaving the important parts of the driving system like the gliders (keeping the train on the rails because I don’t use the actual wheel models themselves). This also led to no change in the bug.
  • Making everything in the train model the same density, this seemed to show some effect on the shaking and glitching but it did not fix it. This is how I knew it was causing the bug.
  • Trying out different gliders, I suspected my gliders could be the issue so I enabled AreContactPointsShown and It seemed like the bogies were jittering side to side a lot no matter what design I came up with.
  • Deleting the track and letting the train travel on the grass, the train behaved differently when the rod constraint was enabled and disabled in this instance. When it was enabled the train started jumping.
    Rod constraint enabled:


    Rod constraint disabled:

Other notes:
This bug wasn’t happening before it started happening around November. I literally went to bed and the train system was working absolutely fine. Then the next morning I wake up with a surprise that my entire train shakes when it moves.

System Information:
Intel(R) Pentium(R) CPU 4417U 2.30GHz
12 GB RAM
Intel(R) HD Graphics 610

Expected behavior

To increase the throttle and the train smoothly making its way along the track with no visible shaking or glitching.

A private message is associated with this bug report

3 Likes

Thanks for your post, I’ll look into this! Do you happen to remember when in November it started?

2 Likes

Hello, I don’t remember as it was a long time ago but I believe it was around the 31st October to 4th of November.

I’m sure that it happened between the 25th October and 6th of November

I do remember looking at any release notes to see if any physics updates happened and I didn’t find any at the time.

1 Like

That’s perfect, thanks! I’ll work on narrowing down any physics changes that might have caused this.

1 Like

Hi again! There aren’t any changes to physics in that time window that jump out at me as potential suspects. I did notice a few issues that lead to unstable simulation:

  1. The CollidableWalls parts are able to collide with each other, which produce large forces when the train turns (the collisions fight to push the walls apart while the rod fights to pull them together)
    image
    I recommend putting the walls between successive train cars into different collision groups so they can’t collide with one another.
  2. You’re applying a LinearVelocity constraint to each train car. When the train is stationary, these constraints get into a “tug of war”: if there’s a small perturbation to the velocity, the first LinearVelocity constraint applies a force to cancel out that perturbation. That force gets transmitted to the second train car (through the RodConstraint), where the other LinearVelocity experiences a perturbation that it tries to cancel out. Since you don’t have ForceLimitsEnabled for these constraints, they apply larger and larger forces until the simulation becomes unstable.

In summary, the train is an overconstrained mechanical system, which are notoriously difficult to simulate stably. I recommend using a single LinearVelocity constraint with ForceLimitsEnabled to move the train.

1 Like

Thank you very much for the detailed explanation, this has really helped me identify the root cause of my issue and it’s definitely not what I expected.

I wish you all the best thank you for solving this.

Happy to help! Detecting these sorts of issues is tricky, we’ll be adding some new visualization options soon that will really help see what’s going on.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.