simple and stable truck physics

Hello all,

I am currently working on a simple exploration tutorial that involves a simple truck. As many of us that have made any kind of racing game, dealing with wheels isn’t simple. I was wondering if anyone knew of any simplified vehicle scripts or possible tricks to give the illusion of driving.

I have tossed around the idea of hiding a 3rd person controller and moving it around like a truck. It was nice and stable, but was too obvious. Maybe with a little tweaking it MIGHT work. However, I might implement a little racing mini-game so having actual car physics might be a plus.

I have taken advise and learned as much as I could from the many tutorials online. I have created a very simple truck(though the axis are all off due to the modeling software but that’s another story) and threw on some wheels and colliders to get a center of gravity. I’ve managed to implement some anti roll bars to help stabilize the vehicle in motion. At the current moment, the goal is for the vehicle to move with more emphasis on stability rather than speed. Which to some extent I have worked out. However, the second my rear wheels(those are the ones that have forward torque force) hit any bumpy surface, I flip end over end.

If anyone has any thoughts or maybe ideas. I would most appreciate it. Till then I’ll be here slamming my head against a wall.

Things currently trying:

-Adjusting center of gravity
-sending a ridiculously powerful force on the wheels if they get airborne
-adjust wheel collider values

Thanks,
Holynub

The official Unity vehicle tutorial includes a “truck” in the ~AlternatePhysicsModel directory that performs very well. By “very well” I mean better than untweaked wheel colliders (it doesn’t use them at all) off-road, or attempting something insane like using the 3rd-person controller to simulate a truck.

The physics used are documented (in terrible English) in a file within this directory. It uses a Pacejka system that is far superior to the wheel colliders, and includes roll-bars, traction control, downforce and aerodynamic friction, suspension… everything you need, just tweak it.

Even the base tutorial does not use the regular wheel colliders, which tells you everything you need to know about attempting to use these bastards on any kind of non moon-based vehicle.

Actually, having said that, I’ve just remembered that I pointed somebody else at this tutorial some time ago. It uses wheel colliders and includes the project for download, and it’s actually a believable enough car for a simple arcadey project. It still suffers from some mad physics-defying behavior, but nothing that you shouldn’t be able to tweak out by adjusting the mass and friction, etc. The gearing seems to be broken which leads to some crazy speed/acceleration, and it also seems to be doing a lot of the work inside Update() instead of FixedUpdate(), which is something else you need to watch out for.

Play around with this (if you haven’t already) and see if you can get something working, then try to apply it to your own truck if it’s suitable, as it’s still simpler than faking wheel colliders with raycasts yourself. Slowing the vehicle down would be a good start

There is nothing actually simple about vehicle physics. But with work you can do it.

Sadly, there are two generalized tutorial types for Unity vehicle physics. The one in xomg’s post and the default post and the standard one you can find in the tutorials section on the site.

The difference, one is basically a roller skate, the other uses wheel physics. The choice is what you want to accomplish in a game. In my setup I used the wheel physics, mostly because I liked the idea that you turn the wheel, not push the car…

The whole process is daunting though. To use that method you have to start by having a decent understanding of how general suspension works and such to get a more realistic car. But there is hope… A couple of things to look at.

WheelColliders:
WheelCollider Tutorial
http://forum.unity3d.com/threads/50643-How-to-make-a-physically-real-stable-car-with-WheelColliders
Pay attention to the section on anti-roll that will make or break your simulation.

The site tutorial:
Site Tutorial

I will tell you that when I developed mine:

I did it with the wheels as separate scripts rather than lumped into one. The main script doesn’t call any wheel functions. It does, however control gears, horsepower, steering and brake through variables, the wheels simply ask the car what it’s doing. What this allowed me to do is to create as many wheels as I wanted and never have to make an array for them.

For each of the wheels, I gave the option of having the wheel define its self. This meant less tweaking in the end. All I had to do was assign gears, max horsepower, max steering and the like… all in the car.

In my first Sim, I created a 57 Chevy, a very fast race car, a semi and a 150 ton crane. I still have a little tweaking to do but the all run very well.

Thanks for the help guys. I really appreciate the feedback. I guess I’ll shelf the good physics till after I’m done with the bulk of this map. It’s not exactly a central component of this game. It’s more for convenience. From what i’ve seen/done, there’s just a lot of trial and error on tweaking the driving controls. Sometimes, I’m not even sure if I actually made any changes.

On a side note, I tried to read that pacejka formula page and my head almost exploded.

Quick update on this. I got bored doing other mini games and decided to tinker with the physics again.

I managed to stabilized the truck depending on it’s speed. The primary source of it’s instability is turning while going at speed. So i created a small “if” statement that would lower the steering angle depending on how fast the truck was moving. So basically you get very stiff minimal steering at high speeds, but more lose steering at lower speeds. This greatly reduced the number of flip instances.

I think Edy is your man. He is unity’s truckmaster or master of big vehicles :wink:

Quick bump on this but. The damndest thing happened when i incorporated a trailer. My truck is now infinitely more stable. Huh… Guess that’s why they build them that way.