Strange wheel collider behaviour

For the last couple of weeks I have been playing around with the wheel colliders with relative success.

My current project has a tank that drives around with terrain-conforming wheels etc etc.

Everything works pretty well but one problem I just can’t seem to find a solution to.

When my tank is heading up steep slopes it seems to get bursts of torque - way more than I have set as the limit for each wheel (200rpm). These bursts can go up to 400rpm or greater and send my normally sluggish tank rocketing up steep inclines. While this is amusing for the first hour or so - here I am a few days later scratching my head and become suitably annoyed.

Does anybody have any ideas?

Thanks,
Lukas

I had one problem quite similar with my car where if my car reached a particular speed it’s unstoppable, a rocket I might add! but does your tank get normal when it return on the flat ground? is the steep downwards or up? it must be something with calculations. You can provide your piece of code and Community may help…

Try:
var throttle : float = Input.GetAxis(“Verticle”);

RPM = Mathf.Clamp(Time.deltatime, 0, 200);

velocity = throttle * RPM; (not tested)

Hey thanks for the suggestion!

While it actually works to a degree it doesn’t solve the problem entirely.

While I clamp the RPM and velocity successfully, the problem is RPM reaches that max velocity too fast. So while I don’t rocket up slopes super fast anymore there is still some kind of “lurching” effect as the wheel RPMs go from zero to maximum in a split second.

When I am going downhill or on level slopes everything is fine - it is only really steep inclines. It seems to be especially evident when one or several wheels are suspended in mid-air and then make contact with the ground again…

Maybe I should just make it a game mechanic? haha jk

I have the same problem, while I havnt tried to fix it yet, I believe the cause is the torque max’s out while the wheel is off the ground offering no resistance.

I suspect the fix will be to cut all torque if the wheel is off the ground.

I’m wondering if anyone has found a solution to this problem.

I am having the same problem. Will try using a raycast to test when wheels are off ground, and if so kill all torque to the wheel.

Wheel colliders have an isGrounded flag… use that instead.

True.
I just tried it. Does not work.

Same effect. Wheels still shoot up slopes…

Anybody have any ideas??

So far I have tried adding slip when going up a steep incline - no effect.
Removing motorTorque when wheels are in the air - no effect.

RPM still jumps from like 100 to over 500 when just starting to go up an incline…

try setting motortorque to zero when it leaves the ground and apply some brake.

I suspect that once the isgrounded test has failed, its possibly too late and the rpm has already shot up.

Something like this:

if (!wheelRR.isGrounded){
    wheelRR.motorTorque = 0;
    wheelRR.brakeTorque = 40;
 }
else {
    wheelRR.motorTorque = engineTorque * Input.GetAxis("Vertical");

Doesn’t seem to work…

Have you had any success fixing your code?

I havnt tried tbh… a different approach might be to manage it based on the rpm as well as isGrounded…

float MaxBrakeForce = 75;

if(wheelRR.rpm > 100 || !wheelRR.isGrounded)
{
   wheelRR.motortorque = 0;
   wheelRR.braketorque = wheelRR.rpm/100f * MaxBrakeForce;
}

I think the problem with this would be that we are limiting RPM to a set number.

I can’t believe there are so little solutions to this. I guess wheelcolliders just aren’t as popular.

I might have to rework my game because I am making a game with a buggy that is off roading. Lots of slopes, and right now I am just shooting off of slopes. Not fun.

sure, but its an arbitrary test number for verification purposes… 100 probably wouldnt be the final number, it would be whatever number feels right to you.

The wheel collider is behaving exactly as youve told it… if you let it spin up really fast, and its slip isnt set correctly its gonna power the car forward when it makes contact.

at some point ill experiment with it… have you looked at the Unity car tutorial, see if theres suffers teh same problem?

I downloaded it this morning but haven’t really gotten a chance to play with it. I’ll take a look later tonight.

BTW - do you have a good way of determining the angle of slope a car is currently on? I am using a Unity terrain and would like to know the angle of slope.

I took a quick video to show exactly what the problem is. Notice how it speeds up going up hills.

https://www.youtube.com/watch?v=xHr14L4Vces

I would look at Unity - Scripting API: Quaternion.Angle

Thank you I will take a look.

BTW I am looking at the Unity car tutorial in the asset store and I don’t see any wheelcollider objects in that car. So I think they are using their own system and no wheelcolliders.

What… really?

Typical Unity… Here’s a car tutorial that doesnt use WheelColliders…

Think this needs one of those scumbag memes…

I would just like to update, I looked at Unity’s car tutorial. Instead of using wheelcollider.motorTorque, they just add force to the rigidbody. I changed my script as well to work similarly, and it works great! No more zooming up inclines…

I also found this. Updated 2014 Unity Assets.

http://blogs.unity3d.com/2014/01/17/new-sample-assets-beta/

This seems to use motorTorque. I will keep testing.

After looking at the Unity 2014 assets… Man they made it really complicated. Sure they are using wheel colliders but making sense of the code is so much more complicated.

More testing and what I found is: Even in Unity 2014 Beta assets where they are using WheelColliders, the cars zoom up the hills. So it must be some kind of issue with the wheel colliders!

Looks like I will be using addForce from now on.

seems counter intuitive to offer a tutorial with wheel colliders that adds force to the rigidbody… just screams we cant get them to work properly either, so we wont bother.

see what U5 brings I guess.

might have to try and figure this problem out myself when I get some time