How to prevent motorcycle from falling over?

Hi everyone,
I’m trying to simulate a motorcycle:

My goal is to prevent the motorcycle from falling over, while still allowing realistic motion, especially on jumps and curved ramps.

One method I tried was add constraint to ground and body (e.g., restricting roll and pitch relative to the ground).
However, this didn’t work well — particularly when the motorcycle moves over looping ramps (curved jumps). It either becomes unstable or behaves unnaturally.

Is there a better way to keep the motorcycle upright, but still allow natural motion over ramps and obstacles?
Maybe a technique with constraints, gyroscopic forces, or another physics trick?

Thanks a lot for any help!

Setting the car’s z inertia to zero seems gets closer to what you want, but it doesn’t get you all the way there and it causes other issues.

See https://playground.babylonjs.com/#IZH3ZT#1.

@Cedric may be able to help more.

1 Like

Thanks a lot for the suggestion and the Playground link! :folded_hands:
Yes, setting the bike’s Z inertia to zero definitely helps — it makes the behavior closer to what I need, but as you said, it still causes some issues in other parts of the simulation.

I’ll try to experiment more with different physics settings.
@Cedric, if you have any tips or ideas on how to better control or disable the constraint only when the bike is off the ground, I’d really appreciate your help.

Thanks again!

Just a small nit-picky thing - remove line 13 (engine creation), which is not needed, and then you will be able to run this playground more than once before needing to reload the page :slight_smile:

i.e. - https://playground.babylonjs.com/#IZH3ZT#4

3 Likes

Oh thanks, that’s helpful! By the way, I’m still waiting for a response to my main question :slightly_smiling_face:

You can lower the center of mass, allowing the motorcycle to lean into the turn, with the lean angle depending on the speed.

4 Likes

Another quick fix would be to limit the allowable tilt and always bring the motorcycle upright when you stop moving (or when only holding W/S keys).

This is a rough test but it appears to work, though the movement stops once the tilt reaches too far.

2 Likes

I think changing rotation not work if physics body of mesh is active.

Lot of great ideas here!
I’d try with what @ilyhandrik did and lower the center of gravity. Like adding and linking a heavy body underneath that doesn’t collide with geometry.

Another solution for extreme situations like very high speed, involving much more work is to use the Physics engine to determine collisions and use your own solver. I don’t know your use case but for motocycle going at 300Km/h with tight controls, it might be the solution.