- Home /
How do I make a custom sliding joint?
(Without wanting to die.)
My game basically calls for a really stupid suspension. I have a car body as a game object, and wheels as a separate game object, and I'm trying to connect them with physics.
The spring joint does nearly everything I want. It's got easy to understand properties that let me set a desired distance and the spring properties. Some more control over the speed would be nice, but it's hardly a deal-breaker. Except I want my spring object locked to my car on the car's local y-axis... and it seems the only way to make a sliding joint is with the configurable joint?
I've tried messing around with it, but I don't understand how it works. Its spring properties don't make the intuitive sense the spring joint does, the drive desired position doesn't seem to work well with spring properties, there's a ton of properties I don't need... I just can't wrap my mind around it.
At one point I tried parenting the wheels to the body, giving them both colliders and controlling the wheel distance manually. The physics bugged out on me a bit because it couldn't really deal with forces, but it may be my best bet.
I also gave a try with raycasts, but I can't figure out how to stop a rigid body from sinking past the raycast distance I want, and I don't particularly want to code all the physics myself just to make those raycasts work properly.