Wheelcolliders

I’m trying to build a general purpose car rig and running into all kinds of interesting issues.

  1. My script allows for front-wheel, rear-wheel, and all-wheel drive. When I switch from rear-wheel drive (the default) to front-wheel the car’s performance drops dramatically. All I’m doing is applying torque to the front wheels instead of the rear wheels…???

  2. My physics is rusty, to say the least, but torque is proportional to power (am I wrong?), so if I want to split the same engine power among four wheels, I should just apply HALF as much power – i.e. torque – to TWICE as many wheels, right? Well, this causes another dramatic drop in performance.

I checked to see if the wheels were staying grounded, and they are.

I can’t figure out how to get the wheels to move in reaction to impacts … they just sit rigidly in place. If I set the spring force high enough I can get the car to flip itself over while standing still…
The wheels have the same settings across the board.

  1. Suspension – as far as I can tell, this stuff just doesn’t work. E.g. if I set the spring target position to 1 then, as far as I can tell from the docs), the rest position of the wheel should move to the far end of the suspension… but nothing happens. Also the direction of the suspension gizmo seems to contradict the docs… i.e. a “NORMAL CAR” has its wheels towards the bottom of the range of motion when nothing is happening, and the usual direction of travel is UP to absorb shocks, but by default the gizmo points DOWN.

98192--3816--$picture_3_256.png
98192--3817--$picture_4_839.png

Oh one thing I just figured out is that the wheel collider gizmo does not give nice feedback … it doesn’t show where the physics engine considers the wheel to be, which is confusing me a good deal. It also makes me wonder if I’m expected to move wheels manually based on its internal state…

You do need to move the wheels yourself unfortunately.

Have you seen JCar on the wiki?

This is a great example of how to do a car IMO.

The suspension wheel position bit is here:

            // let the wheels contact the ground, if no groundhit extend max suspension distance
            Vector3 lp = w.transform.localPosition;
            if (col.GetGroundHit(out hit)) {
                lp.y -= Vector3.Dot(w.transform.position - hit.point, transform.up) - col.radius;
                floorContact = floorContact || (w.motor);
            }
            else {
                lp.y = w.startPos.y - suspensionDistance;
            }
            w.transform.localPosition = lp;

There is a car in an official unity project you can take a look at too. It is in the networking example project. It doesn’t handle well, but it is a working example.

A couple of people mentioned it. I’m not sure it’s gotten much further than I have (except in the implementation of a gearbox – so far my car simply delivers maximum torque all the time :slight_smile:

The more I look at it, the more it seems that wheelcolliders don’t really work… just look at this snippet:

            // see docs, haven't really managed to get this work
            // like i would but just try out a fiddle with it.
            WheelFrictionCurve fc = col.forwardFriction;
            fc.asymptoteValue = 5000.0f;
            fc.extremumSlip = 2.0f;
            fc.asymptoteSlip = 20.0f;
            fc.stiffness = fwdStiffness;
            col.forwardFriction = fc;
            fc = col.sidewaysFriction;
            fc.asymptoteValue = 7500.0f;
            fc.asymptoteSlip = 2.0f;
            fc.stiffness = swyStiffness;
            col.sidewaysFriction = fc;

It really seems to me that someone at Unity should have this working properly … or else how was it tested?

It doesn’t help that you can’t give anything a mass of 1000 or more :-/

The wheelcolliders weren’t created by unity, they are part of PhysX. Nobody seems to know what that damn friction curve is all about.

I mentioned a bit about it in this thread:
http://forum.unity3d.com/viewtopic.php?t=12465&highlight=wheelcollider

ikiman did a good job of using the wheelcolliders without fudging the values and interfering with the physics too much:
http://forum.unity3d.com/viewtopic.php?t=14086&highlight=

And I managed to get them to work pretty good in my game (which may appear in my signature if I set it up right…), but I was aiming for arcade-style physics. And I do a lot of interfering with the physics.

I like invincicar (nice job on the paint material btw, and also very atmospheric sound) – but it seems like your car is glued to the ground, and I don’t see any suspension-like movement – e.g. the car doesn’t “lean” on its suspension as you turn.

This is exactly the problem I’ve having with getting my cars to behave “nicely”. I want cars to get airborne as they go over bumps, and be able to do spectacular rolls and crashes, but I don’t want them to be uncontrollable … I’d say my model would be Grand Theft Auto – realistic enough to feel like you’re driving a real car but not so realistic that you can’t drive at 140mph through city traffic…

I might note that the rigidity of the wheelcollider’s “suspension” causes quite a bit of instability AND makes the car harder to control… since you don’t get the visual feedback (your car starting to lean on its suspension) you don’t know how far you can push it, and then when the car starts to roll or flip, the suspension doesn’t absorb anything, so you get this “my car is a cardboard box” feel.

Anyhow, I guess if wheelcolliders are a thin wrapper around a PhysX entity that doesn’t work properly, that pretty much explains everything. It seems like I’m probably best off simply implementing suspension from scratch, and giving up on the wheelcolliders altogether.

I was learn JCar and gettin stucked in steering, wheel and moving backward.
When car hit something it won’t move backward n keep forward, so everything stucked and get to endtask.
Is there any sample code or guide references for creating moving backward acceleration on JCar iPhone?
Any suggest would so appreciated.
Thanks all.