# Please, someone help me understand joints!

I have one rigidbody (a wheel) attached to another (cars body) via a configurable joint and have a spring between them.
I want the wheel to move up/down (this part works), side-to-side, rotate around the Z and Y axes.
I want to freeze the latter ones position and rotations and set them myself through code. Is this possible?

So far all I got was jello wheels. I only need a spring for the Y axis. I’ve seen that there are angular springs and individual limits, but that just gives a stiffer jello wheel. Even if I would want springs, I don’t see any option to set it for each individual axis, there’s only one linear limit and spring limit and a combined spring for Y and Z rotation.
What am I missing?

Hi,

I tried to set up suspension, steering and tyre flex using ConfigurableJoint ages ago, and I had jello problems too.
I know it’s possible to do suspension with ConfigurableJoint, and I’ve seen some very impressive projects using Rigidbody for all kinds of things, I just didn’t have any luck myself. I’m not any kind of expert on PhysX joints. I couldn’t manage to get anything that worked at speed, and coped with hard collisions, without some degree of jelly ruining everything.
I think you get less jello if the masses on each end of each joint are similar in magnitude (like, mass ratio isn’t 50:1), if that’s an option (apologies if you already know this). I think Joint.massScale is supposed to help with this, but I only tried it a tiny bit because I’d got excited about ArticulationBody by that piont.

I’ve got stuff working now with a hierarchy of ArticulationBody instead, which seems much more intuitive to me (it mostly just worked straight away, I think they’re designed to avoid jelly:).
I’m using a frictionless MeshCollider for my wheels (with a modified Edy Vehicle Physics handling friction/drive etc), with ArticulationBody’s PrismaticJoint handling the suspension and tyre flex, and RevoluteJoint handling the steering.
I’m not any kind of expert on ArticulationBody either btw:) But, the stuff seems to work reasonably well now.
That said, it’s not been easy. There are many problems with this approach, depending on what you want from it, which I’ve had to code around. I think the farther away you get from regular road vehicles doing road driving, the harder everything becomes.

I’ve been noodling around with monster truck physics since 2016, and doing analogous work for an in-production game for about a year and a half now (on wheel physics and other stuff).

Good luck!

Oh… I wanted to look into that a while ago, but completely forgot about it.

I’m not sure how far down the vehicle physics rabbit hole did you go, but I wanted to have a more realistic suspension, to separate the sprung and unsprung mass, for more realistic weight transfer. I thought a lot about how I could do this with the least amount of headache(for now) and I couldn’t really find another solution other than using multiple connected rigidbodies. Raycasting with 1 rigidbody didn’t work, because if I remove the unsprung weight I have realistic weight transfer, but unrealistic acceleration and vice versa.

Using joints though, I had problems right of the bat. Granted there wasn’t any friction applied, but when I applied force to any rigidbodies, after a while the car started to slide and slightly rotate around the Y axis and sometimes with the same combined mass it accelerated faster than the 1 rigidbody car. Interestingly, if I restricted the X axis on the cars rigidbody, everything was solved. Magic stuff right there…

I didn’t. As a matter of fact, it didn’t even cross my mind. I assumed physics work like in real life out of the box and you tweak it if you want a different behavior not the other way around. What I understand from this then, that I shouldn’t bother anymore with using joints, because even if I manage to get it to work somewhat with cars, I won’t really get good result if I want a larger truck that’s hauling ~40 tons at some point anyway.

All I need from this is to be able to separate sprung and unsprung weight, make the wheels move up/down with a realistic suspension and side to side(for track width changes) and to be able to rotate the wheels for steering/ toe and camber (although the latter ones can be solved in another way).

Haha, I’ve ended up stuck in very specific bits of the vehicle physics rabbit hole, but am pretty ignorant about others.
In 2016 I couldn’t find a good monster truck game for my son, so I naively thought I’d make one.
I started with Edy’s Vehicle Physics, which is great, it’s cheap and the code’s clean and it you can set up and configure a drivable vehicle pretty quickly (although even though it’s pretty simple, there are still a bucketload of things you can fiddle with, so it was kindof daunting to 2016 novice me).
We’re using Vehicle Physics Pro in Exo Rally Championship, and it lets you configure everything. If you’re after realism, the VPP developer’s using it in some quite simulatory simulators and really seems to know his stuff & actually races IRL. I don’t race IRL, so I can’t vouch personally for the accuracy, but it seems to be working well in our game right now:) I’d’ve thought decent weight transfer would be necessary for any kind of realistic vehicle simulation. You could give the free VPP a go, if you haven’t already.
There’s a comparison of Edy’s products here.

Both products use the Unity/PhysX WheelCollider though, and while I guess it’s decent for non-stunt road driving (suspension still instantly “snaps” to the road surface, rather than elongating “gradually” like a spring would though), that single-raycast-based wheel collider is garbage for weird terrain or wheels that aren’t “protected” by the body/chassis collider (like monster trucks) or doing stunts (no proper monster truck wheelies </3).

So I’ve ended up using frictionless mesh colliders on PrismaticJoint springs for the wheels that present the same interface to Edy’s stuff as the Unity WheelCollider so he can deal with all the complicated friction & drivetrain stuff. Niko Stenberg suggested this to me, he’s awesome:)
Edy’s stuff takes care of nonsense like skating sideways for “no reason”, rotating around y, jitter and stuff.

I guess if you’re using joints, you’re doing something similar. I feel like the approach I’m using would let you separate sprung and unsprung mass. ArticulationBody seems far more forgiving with larger mass ratios than my experience of ConfigurableJoint. Our vehicle weighs ~2400-3600kg with 60kg wheels, although I had to crank the physics timestep & solver iterations (may be able to de-crank, haven’t revisited). I set my ArticulationBody hierarchy up with real-world values and it all just worked first time.
I think weight transfer should “just work”, if the centre of mass, springs & weight distribution are correct.
VPP gives you a tool for configuring the inertia tensor, which I think has an effect on weight transfer and handling generally. IIRC Edy says the one Unity computes for you is bad for vehicle behaviour. Certainly, using the VPP tool made my monster trucks much more lively.
The XRC rover has steering, toe and camber (toe and camber aren’t modifiable while driving right now, but probably could be).

Edy’s configured some huge and complicated vehicles with joints, and you can pay him to set up a vehicle for you in VPP, if you have enough real-world data, so I don’t know if huge trucks with joints are an impossibility (40 tons is 7x bigger than my monster truck, 10x bigger than the XRC rover). You can maybe cheat by dumping some mass into the wheels or articulation hierarchy:)

Sliding the wheel mesh over bumpy terrain, both meshes are of course entirely rigid so you need to do trickery to get a smooth ride & prevent the wheels pinging up all over the place when you hit tiny bumps. I’m using a combination of a second set of springs to simulate tyre flex, and contact modification to give a bit of extra squish.
Most of the motivation for my approach was I needed “3D”/ “Volumetric” wheels, rather than raycasts, though; you maybe don’t, I don’t know.
Traversing “seams” between meshes can be awkward (not sure I’d recommend the default contact mod offset “fix”).
I’ve discovered, reported, and had some awkward/nasty bugs fixed in both ArticulationBody and ContactModification, so I’m not sure how much use they’re getting in the wild.
I’m still not sure what to do with sidewall-only contacts, like when the vehicle has a z-rotation of 90:)
Because WheelCollider can only present a single point of contact, that’s all I’m doing for now, but I guess ideally I’d be able to present, e.g., a ground-contact and a front-tyre-wall contact simultaneously, e.g., for backflips (backflips work OK rn though, so maybe I’ll leave it:).

I’ve no idea if the DOTS Unity Physics or Havok stuff will address any of this or be a better solution generally. None of it existed when I started out:)
PhysX 5.1 has some cool-sounding stuff that I’m sure would help (soft bodies?!), but I guess we’re years off seeing that in Unity</3.

Edit: We had to buy the “Enterprise Edition” source to use VPP with our custom wheel mesh collider. I think Edy has plans to make custom wheel colliders possible at “pro” level, but last time I checked it hadn’t arrived there yet. EVP comes with source anyway.

Thought I’d ask before bombarding you with random vehicle dynamics terms.

I’m aware of Edy’s work, but I wanted to do things on my own. Besides there is no point in using a pre-existing package if you will have to rewrite a good chunk of it, is there?

Decent weight transfer is there, it’s just too much. The car is perfectly driveable until you get to the limit, then it spins out a little too easily. It could be the friction curve or how the forces are combined, but more than likely the excessive weight transfer doesn’t help.

That’s certainly one of the side-effects of properly modeling the suspension that I’m after. Over rough terrain at high speeds wheel hop is, in my opinion, an important factor that shouldn’t be overlooked. With the current implementation, the car would be way to fast in the straight line, because instead the wheels being in the air half the time doing nothing, they would be on ground, constantly accelerating the car.

I switched from 1 raycast to 3 not so long ago, one on each side and one in the middle. It’s only for suspension for now, but it kind of was a necessary step, if I ever decide that I want to simulate tire forces more accurately and tire temperatures in different sections.
I looked into shape cast wheels, but didn’t bother much with them, I don’t need the accurate collision just yet.

I’d try to make a few raycast from the sidewall and apply forces in the right direction, that’s the best solution my 4am brain can think of.

I have to look into these articulation bodies, because seemingly there is no way that I can achieve what I want with joints.

Oh! I knew this was in physX, but I didn’t realise it had made it to Unity yet:
https://docs.unity3d.com/ScriptReference/WheelCollider-suspensionExpansionLimited.html

The experimental branch of VPP has separate lateral and longitudinal friction stuff going on; I’m not sure if it’s made it to the master branch yet.

Good luck with it all, anyway!