Hello, developers!
I’m having trouble balancing a two-wheeled vehicle. I’ve tried everything I could find — PID, BodyGyro, and other methods — but nothing seems to work. In the end, I managed to keep it upright, but the vehicle handled poorly at high speeds because of my method.
I’d really appreciate any advice on the best way to keep a two-wheeled vehicle upright while still allowing it to steer properly.
Make a hidden 3rd wheel to keep it up.. That’s what I did anyways.
Thank you for the reply, but I don’t want to do it in some janky way. I need a proper method that I can improve and turn into a realistic two-wheeled vehicle.
Pretty sure most examples out there either use some variation of a 3/4 wheeled vehicle with the wheels hidden and the two wheels you see are actually just made to rotate with the other ones. You could also pursue a custom physics route, but that may be too time consuming for your purposes.
Raycasting off the side of the vehicle to see how close it is to tipping over and then stopping the tipping if it’s too close might work.
I just realized how bad this drawing is lol
Good luck, it would be interesting programming. Keep in mind not everything you see in a program is what you are seeing. The art of program deception is a skill within itself. You see this in most every game (without seeing it).
To do this for real I think I would try for a inverted pendulum approach..
Here is a concept scratch script. Again sounds interesting, but this will need some love..
local veh = script.Parent
local body = veh.Body
local gyro = Instance.new("BodyGyro", body)
gyro.MaxTorque = Vector3.new(0,0,math.huge)
gyro.CFrame = body.CFrame
local hingeL = body.WheelL.HingeConstraint
local hingeR = body.WheelR.HingeConstraint
local function step()
local tilt = body.Orientation.Z
gyro.CFrame = CFrame.Angles(0,body.Orientation.Y*math.pi/180,0)
local pwr = math.clamp(-tilt*2, -50, 50)
hingeL.MotorMaxTorque = 10000
hingeR.MotorMaxTorque = 10000
hingeL.MotorMaxTorque = 10000
hingeL.MotorMaxTorque = 10000
hingeL.TargetAngle = pwr
hingeR.TargetAngle = -pwr
end
game:GetService("RunService").Heartbeat:Connect(step)
I needed something like this and it is so smart Ill try to implement it after I get done making the suspensions for the motorcycle. My mind was blown reading that ![]()
Check my post! In the model there is a Balancer (part)
You can use it to balance your vehicle. Still I dont know if u are tryna make a motorcycle. I have the same issue. Maybe you can try to rotate the gyro? As for me it didnt work but maybe its worth a shot.
edit: this is probably 100% wrong lol
How to possibly use this? I dont understand anything from it.
I wouldn’t .. I’d make a 3rd 4th wheel. I’ve seen Segway tools doing this with only two wheels.
Nothing better than a working model to learn from. Many in the toolbox.
Not sure if this would work, but check into AlingOrientation and AlingPosition
starts glitching out ngl it does balance tho cant turn
I’m going to try using raycasting over the next few days and let you know how it turns out.
Just use AlignOrientation instead? λ
If your goal is only to restrict rotation on the z-axis, using an align orientation set up like this should work.
The Attachment0 should have an orientation of (-90, 0, 0)
I’ll add that the raycasting idea does tell you if you’re off-balance on any one side, but correcting the balance is another story, and probably more trouble than it’s worth. If you’re going for realism, restricting any rotation at all kinda goes against that given that bicycles and motorcycles tilt as they turn.

