Download

How to stabilize a bike?

How do I stabilize a 2 wheeled bike? I want to ride in any direction, but when I turn, I want the bike to stay up straight and not tip/fall over.

The easiest way, if you don’t want to go into bike physics, is to lock the X rotation. You can find that under Constraints in the Physics section of the actor’s property panel.

With that I run into the problem of it only working on the X rotation and I don’t want to lock it on multiple rotations.

Sorry, I am afraid I don’t understand your comment. Can you try to explain it differently? Maybe with a drawing?

First what kind of bike you are creating? Physics or just model with animations? Be more precise of what you are doing , what you want get and what are problems. It is quite hard to guess without that information.

also you can always google to get some results like:
https://forums.unrealengine.com/community/work-in-progress/115275-wip-wheelz2-physics-bike-game

Ask that guy maybe he is willing to share how he did them.

Not at home atm. I’ll try to explain as best as possible. I am trying to create a bike that you can casually ride with on a track lets say. The bike is a motocross type bike and I want to be able to lean in the corners, the problem im running into is if I disable X rotation, and lets say I turn around a corner, the rotation will “unlock” itself. I also want to be able to jump. I’ve realized that I should start using actual code, cause it seems like that will make my life easier.

If you are going to use rigid body physics simulation for body of the bike, you will have to do everything using forces and torques. In this case the “simplest” solution is a PID controller that will apply just enough force to keep bike up (or any other direction necessary). There is example of such controller in MMT’s “simple examples” level. (project in my signature).
But if you go down this path you will have to do some extra work, like running physics related calculations on physics sub-steps and using different set of nodes to get transforms of the objects. Multiplayer will be a big challenge too.
Look at alternatives - kinematic bike (animated by some rules), unless you really need physically simulated one.

Hi

On a physics example
Try lowering the centre of mass to below the wheel contact line,
you may have to try different depths, this does let your bike bank inwards on corners and will stand vertically if not moving.
try -200 to start with in the z centre of mass offset.
As a note…
You can add extra physics bodies (with all collision set to ignore) below the bike to achieve the same mass offset.
You could for example add a sphere physic body below both front and rear wheels
Experimentation time

Paul G (Sly)

Thanks, sounds sweet. I’ll have a look into that! :slight_smile:

Thank you very much! :slight_smile: I will also have a look into that. Thinking that I might have to take a new alternative like a kinematic bike as you said. Thanks again! :slight_smile: