2
\$\begingroup\$

I am currently developing a game, motorcycle type game. Of course, my map is not just made up of simple line or curve. For example: a vertical circular track in the map. i've seen most 2D motorcycle games have this design.

How do you prevent the motorcycle from falling off the vertical circular track by correlating the motorcycle's forward speed? If the forward speed is 0, it will fall down naturally, because this is the physical essence, but if the speed is fast enough, it should firmly grasp the track and not fall down. so how to exert force on it to counteracting gravity? what's math behind it? looking forward to your reply,i really appreciate it, thank you!

\$\endgroup\$
  • 1
    \$\begingroup\$ What physics engine do you use? Do you mean real physics or some fake visual behaviour? \$\endgroup\$ – Anton Petrov Oct 13 '18 at 14:25
2
\$\begingroup\$

A proper looping should work out-of-the-box in a good physics engine. "Proper" in this context means that the upside-down section is constantly curved. As long as the curving forces the vehicle to change its direction, the resulting centrifugal centripetal whatever force should cause it to cling to the track.

If it doesn't work, then possible reasons could be:

  • The vehicle is not fast enough
  • The looping is not tight enough
  • The collider of the looping is not smooth enough
  • You are somehow adding artificial force or torque which interferes with the simulation
  • The physics engine itself is not very realistic

But when you want the vehicle to drive through a half-loop and then drive along a straight segment upside-down for a while without falling: I'm sorry, but this is not how physics work in real life. So if your physics engine makes the vehicle fall off in this situation, then it is working as intended. So if you want the players to be able to drive on the ceiling under certain conditions (which I can understand, because it looks and feels awesome), then you need to cheat. Detect this situation and temporarily switch off gravity for that vehicle. Remember to switch gravity back on again if the wheels disconnect from the straight section for any reason, if the player breaks or if the straight section ends.

I'm looking forward to playing your game.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.