# Is there a way to gently apply brakes to a wheel collider?

Discussion in 'Physics' started by georgeq, Mar 20, 2016.

1. ### georgeq

Joined:
Mar 5, 2014
Posts:
452
I have a vehicle implemented with wheelcolliders the acceleration process works fine as it is proportional to the motorTorque I apply to the wheels, the higher the torque the faster the vehicle reaches maximum speed. However when braking, the vehicle always reaches full stop in the same amount of time, no matter if I apply a brakeTorque of 0.01 or 10,000, is the equivalent of applying the full brake power just by slightly touching the brake pedal.

### Digital ApeModerator

Joined:
Apr 11, 2010
Posts:
25,221
Sounds like your masses / or scale are so far out of whack tbh - or bugged. I have to give it a fair amount of break torque to slow it down / keep it from rolling on a hill.

Given 1 unit = 1 meter scale (so a car is a few meters), and a car mass of around 1000 kg, it should function as you expect with wheel masses of 20 to 30 each.

3. ### georgeq

Joined:
Mar 5, 2014
Posts:
452
I'm simulating a cargo truck, so I set up the mass of the vehicle to 8,000kg, and left the wheel's mass in the default 20kg, with that setup no matter how much brakeTorque you apply it's always as if you push the brake pedal to the metal. With you advice I started playing with the mass of the vehicle, with a mass between 1,000kg and 3,000kg the truck slows down proportionally to the applied brakeTorque... if I set the truck's mass to 8,000kg and the wheel mass to 100kg, then the vehicle behaves as expected...

I think what happens is that, a small wheel mass on a heavy vehicle causes the wheels to fully stop with a minimum brakeTorque, which causes maximum friction with the floor, and this is equivalent to step in the brake pedal with all your strength. Am I right?... I'm not sure this is the way real wheels behave.

Probably some time latter in the development of my project, the truck will need to carry some cargo, this dependency of the wheel mass based on the vehicle's mass may imply a problem... Is there a formula to calculate the wheel mass based on the vehicle's mass or should I figure it out empirically?

### Digital ApeModerator

Joined:
Apr 11, 2010
Posts:
25,221
This sounds like either a physx bug or maybe truck wheels do weigh a fair bit more. I know the man with the answer though and it's @Edy - perhaps shoot him a PM for some advice here. He does love bigger vehicles

5. ### Edy

Joined:
Jun 3, 2010
Posts:
1,459
I think it's a PhysX issue due to the bad implementation of the wheel, which exhibits numeric instabilities and side effects easily under some common combinations of parameters.

Don't expect the WheelCollider to always behave in a realistic way. Personally I have been unable to find any logic on the WheelCollider's torques and forces (I ended implementing my own solutions). But I've found that some values have great effect in the WheelCollider stability. This is the case of the suspension dampers for example, and according to your comments I can guess that the wheel mass has a big influence as well.

A couple of workarounds for you to try:
• Keep the wheel mass related to the vehicle mass. For instance, set "wheel.mass = rigidbody.mass * someFactor" instead of assigning an absolute value. You might then experiment with someFactor starting at 0.01. The WheelCollider.mass value has little effect in the physic simulation (wheels don't "weight", their masses don't sum to the vehicle's mass), but a big influence in the numeric stability.
• Increase the number of substeps via WheelCollider.ConfigureVehicleSubsteps. The drawback here is that any number other than 1 adversely affects the suspension: effective spring rates seem to change, and WheelHit.force reports wrong forces (the sum of all forces doesn't match the vehicle's weight). You should consider whether having more substeps pays off these drawbacks.
Some tech insights:

In a typical wheel simulation the wheel mass is used to calculate the wheel's inertia and angular velocity (as angular velocity = angular momentum / inertia). A good implementation accounts for all torques, tire friction, tire forces, etc. in a way that even low wheel masses respond correctly to the torques applied. However, it seems that in PhysX the tire friction and forces are not included in the calculations correctly. This would explain the effect you observe with low wheel masses: the brake torque causes a change in the angular momentum -> the small mass-inertia causes a large change in the angular velocity -> such large change while braking causes the wheel to fully stop.

@hippocoder thanks for the mention!

georgeq likes this.
6. ### georgeq

Joined:
Mar 5, 2014
Posts:
452

So what you say is that the best way to achieve the desired behavior is by empirical methods. To setup a wheelcollider is not that hard if you know the right parameters or if you have a method to figure them up quickly, but when you are having your first experience with them it can be quite hard, specially if your scene contains hills as the torque needed to start moving the vehicle on a slope is greater than the one required on a horizontal surface.

7. ### georgeq

Joined:
Mar 5, 2014
Posts:
452
Well... it seems I'm now in the right track to develop an autopilot capable of keeping speed within a descent stable range no matter if the vehicle is going up hill, down hill or on a horizontally flat surface, the only thing is that to achieve stability I had to set the wheel mass to 2000kg which is a ridiculous value considering the mass of the vehicle is 8000kg.

8. ### JamesLeeNZ

Joined:
Nov 15, 2011
Posts:
5,618
you know, you dont have to set the mass to 8000 because thats real weight. Youre making a game, if it feels right/plays how you want without using real values, go with what works rather than making your life hard trying to get real world numbers to work. The player is not going to know that the mass you used is 2000 rather than 8000.

If you get stuck, try my automagic wheel controller thing in sig. Ive never had any problems like yours.

9. ### SepraB

Joined:
Sep 14, 2016
Posts:
3

I have exactly the same issue as you. No matter the amount of breakTorque I use, background calculations drops the RPMs and wheels speed to zero. And I don't want to modify any mass because the vehicle looks to work properly in its other features.

10. ### ackro

Joined:
Aug 15, 2014
Posts:
2
braketorque is never worked for me. use wheel damping rate or rigidbody drag to slow down vehicle gently.