Tank slipping on the slopes

Hello,
I’ve a tank which is composed of the mainbody, wheels, tracks, … . Only mainbody and wheels (and joints connecting the wheels to the main body) have rigidbody. The wheels are implemented using sphere colliders. The movement of tanks is done adding torque to the wheels.
Now, the problem is that the tank is slipping on the slopes. As first I though that it is a physics material problem, but I’ve set different combinations of the friction values, but without success. It looks like the terrain is made of ice or what :slight_smile: I’ve read that the most common solution is “manually” handling the slipping in code. But I want to know the culprit, why is it happening? Because if the physics materials have proper friction set, there should be no sliding whatsoever. Or am I missing something?

Thanks

Even with friction 1.0 you can’t climb a surface beyond what that would allow (I suppose the arctangent of the friction coefficient, so 45 degrees), and that’s not even including the transient contacts of the physics system, as it discretely emulates the motions.

A quick test with two long flat colliders in full contact shows that I can go way beyond that with 1.0 friction, up to somewhere between 60 degrees and 70 degrees and then it starts to slide, but that’s totally static. Any motion could jostle the colliders out of contact for a frame, allowing things to slide.

This asset has a cool setup tank that can climb pretty steep stuff, but no idea how steep exactly:

1 Like

Change the drag dynamically when going up slopes

1 Like

First, ensure to configure friction and collisions properly in Unity. There’s an unique combination of settings that make friction realistic: Patch Friction Type + Improved Patch Friction. All other combos produce non-realistic and inconsistent results. More info:

Additionally, I’d recommend to configure the solver type as Projected Gauss Seidel.

With that configured, I’d try setting up a simple scene with the tank rigidbody and colliders, but without any code. Create a physics materials for the track spheres and for the ground. You may use a large plane as ground. Assign the materials properly.

Then you can put the tank on top of planes with different angles, and check the results. The tank will keep static on a given slope as long as the combined friction of both wheels and ground physics materials allows it to do so:

  • If the combined friction is too small, the tank will slide.
  • If it’s large enough, the tank will keep static.
  • If the friction is large enough, and the slope is pronounced enough, and the center of mass of the tank is high enough, then the tank will roll over down the slope.

You may play with the physics materials in real time from the inspector and check the results.

When you have this part working as expected, you can then add code to apply forces and/or modify the friction of the wheels dynamically. Notes:

  • Any applied force will have to overcome the friction to move the tank.
  • Physics Materials are shared between all objects they’re assigned to.
  • Friction values may be larger than 1.
1 Like

Thank you for all the replies.

@Kurt-Dekker Fortunately, I’m using one of the paid Chobi’s asset (PTM), albeit heavily modified to suit my needs.

@Edy Thanks for your detailed response. I’ll try the stuff you posted and will respond to this thread later (as this my hobby project and wouldn’t have the spare time till the weekend) to report my results.

@Edy,
so I’ve set the physics settings as provided in the given thread, set the sample scene, assigned the physics material, but the tank is still sliding. I’ve also tried to set friction like 1x10e6 and the tank was still sliding back.

I’ve also tried the raw PTM tank in the sample scene and the results were same (I just wanted to be sure that there isn’t something wrong with my modifications).

I know that trying to help through the forums with problem like this (where there is specific configuration of objects, physics stuff, etc.) isn’t easy if not impossible, but I just want to know if the problem is on my side or is this expected behavior.

I’ve tried to make the simple “anti-slipping” code (with the help of PTM) which fix the issue in some extent (but creates other problems) so maybe I’ll go in this direction until I find some other solution/culprit.

Then it must be a problem with the code or the settings. Physics friction is working correctly on Unity. I’ve just set a very basic test scene with a “vehicle” mock up consisting of a box and four sphere colliders, and it keeps perfectly static on very pronounced slopes:

The rigidbody:

The physics material in the ground:

The physics material in the “vehicle”:

The physics settings:

1 Like

Thank you very much for your reply.

I think that problem could be how my tank is composed. In my case it is like that:
MainBody (Rigidbody, MeshColliders) <- Suspension (Rigidbody, HingeJoint, SpehereCollider) <- Wheel (Rigidbody, HingeJoint, SpehereCollider).

So maybe those hinge joints are breaking it somehow? I’m attaching wheel, suspension and mainbody components, just in case:
Wheel


Suspension

MainBody

Is the tank slipping/sliding down the slope or is it rolling?. If you enable the Gizmos in the game view and select one of the wheels you’ll be able to see the collider. You’ll then be able to see if the wheel is rolling or sliding.

It’s not possible to prevent a sphere from rolling down a slope with friction alone. Friction only prevents sliding. And in Unity a very high angular drag setting can’t prevent a sphere from rolling down a slope and this may also extend to joints. Angular drag can only reduce the roll rate.

If your issue is caused by rolling then when the tank is on a slope you may need to add some extra force to compensate for the slight creeping down slopes. You could also control the wheel using the motor and target velocity setting. Or maybe switch to using a wheel collider.

1 Like

Actually the wheels are rolling. I apologize for using wrong term.

By extra force you mean to add some downforce to “pin” it more to the ground or just add some additional force in the direction of the movement? I’ll look also at the motor in the doc.

Adding more downwards force will make it even worse because gravity is what’s causing the issue. Gravity is constantly trying to push the tank down the slope and so when wanting to stop on a slope your script will need to counter gravity by giving the wheels a slight force to send the tank up the slope.

Some player controllers will cheat a little and just disable gravity on a rigidbody when stopping on slopes.

All games cheat. Remember, it’s a simulation anyway, it’s not real, so focus on getting the exact user experience you want, even if it involves what you happen to label as “cheating.” Adding a little extra up force to prevent downhill slippage is par for the course, imnsho.

Generally speaking games are Potemkin Villages. There isn’t really a tank, there isn’t a motor, there isn’t a transmission, fuel tank, fuel filter, internal combustion, engine response time, throttle curves, etc.

But there can still be fun. That’s your job. :slight_smile:

1 Like

I don’t have experience with Hinge Joints (I always use Configurable Joints), but I think you should be able to prevent the sphere from rolling by setting a target position and a spring and damper in the wheels’ joints (similar to what you do with suspension).

1 Like

I agree, maybe I made a wrong impression, but I don’t care if the solution hack as long as it works.

So after some coding I’ve made an anti-slip function which is working okish (but need more testing). I was trying to post the video, but it won’t accept the .mp4, shame.

By sliding you mean that wheels are “locked” and they’re just sliding without any movement? Because for instance if my tank does approach slope from the side, than without the anti-slip code, it just slowly “slides” downwards but with wheels rotating (it’s shame I cannot post the video). This is also expected behavior? Do you, or someone else reading this thread, has some link where this is explained in more deepth? Or is my only option to read the PhysX docs?

Edit: Attached videos
videos.zip (4.8 MB)

Thanks, will try.

A potential issue with that setup is the difference of mass between the elements. The chain of joints is supporting objects with masses 8000-100-100. When the mass ratio between the attached objects is larger than 10:1, joints tend to “relax” and behave as soft constraints. Posible fixes:

  • Reduce mass ratios. For example, set the suspension and wheel masses to 1000 and 500 respectively (and reduce the increased mass from the main body’s mass).
  • Increase the physics rate. Default is 50 Hz (Time > Fixed Timestep = 0.02). Increasing it to 100 Hz (Fixed Timestep = 0.01) is enough to handle these mass ratios.
3 Likes

Ok, so I’ve modified the masses and it looks like it is behaving OK, now (I’m attaching the video)! So looks like the mass ratios was causing it all along?

I’m running physics manually from the code with the frequency of 60 Hz (what you actually see in the video is “replay”) and I don’t know if increasing the physics to 100 Hz would be possible (performance reasons).

without-anti-slip-mod.zip (7.5 MB)

1 Like