How would I add friction to a HingeJoint?

Godot Version

Godot v4.6

Question

I’m trying to make a 2d racing game with a car that can accelerate and brake using a couple of wheels. Problem is, there’s no way to add a real braking effect to these wheels yet as far as I’m aware.

What I’m looking for is a way to apply rotational friction between the wheel and the body of the car, kind of like unity’s old “Friction Joint 2D.” I know that the pin joint has a motor and some angular limits, but it lacks any kind of friction variables. I’ve tried boosting the wheel’s angular dampening in the generic physics settings to achieve a similar effect, but it felt floaty and the car would never come to a complete stop. I’ve also tried just outright disabling the wheel’s rotation too by locking it’s global rotation, but it feels too harsh and sudden. This has been something that has been annoying me for the past couple years.

I probably need to make a custom physics integrator or something, but I don’t know where to start. What would even be the math for something like this?

Is this an old project you’ve upgrade to 4.6 or a new one you made in 4.6. If the latter, your physics engine is still the old Godot one. Try changing it to Jolt and see if it’s better.

I’d try limiting the amount it can rotate every frame with clamp() and lerp() the down over every frame.

I poked around in a new 4.6 project again yesterday and Jolt doesn’t offer any new stuff along the lines of friction. Jolt can’t even be used in 2D afaik.

I’ve tried using hinge limits before too in the same way, but I could never get that method to behave in a way that makes any sense, except locking the wheel outright.

Locking the wheel rotation entirely doesn’t get the desired effect, even though it’s technically doing the right thing. I want a real braking effect where the car body and wheel are physically related to each other. Increasing the joint’s rotational friction should gradually slow the car to a stop AND also gradually increase how much rotational energy from the wheel is being transferred into the rest of the body.

I missed this was 2D. Sorry. Have you looked at Rapier?

So if this is fun for you, keep going down this path.

But keep in mind that at their cores, games are at best physics simulators. They are faking it. The player will not know how you implement braking. If it fulfills some desire in you to make it as close to the real world as possible, more power to you. But if you’re trying to make a fun game that feels good to play, I’d recommend taking a step back and making it easier. Just apply braking to the entire car at a higher level and move on.

That’s the point yeah. I want to use real physics. Godot is missing a component i’m looking for, and I need help figuring out how to make it myself.

I don’t know your background. I studied Calculus, Physics, Differential Equations, and took an entire class on Physics in Computers and Video Games in college. I’ve been professionally programming for 30 years. The actual physics calculations required in the 16.6667 milliseconds a typical physics frame takes (60/second by default in Godot) are not possible. There are lots of shortcuts being taken under the hood because it’s good enough.

I would say you want to use the most real physics you can. But you do you.


I looked up Unity’s Friction Joint 2D and how it worked. This was in the notes:

Use the Friction Joint 2D to slow down movement between two points to a stop. This joint’s aim is to maintain a zero relative linear and angular offset between two points. Those two points can be two Rigidbody 2D components or a Rigidbody 2D component and a fixed position in the world.

So I’d say that’s your answer. Which is use a PhysicsMaterial on your RigidBody2D nodes.

Then you can programmatically change their friction over time - or just move them into contact like an actual braking system. This article on Disc and Drum brakes shows how you can move the calipers. (I’m assuming you’re using disc brakes because this is a racing game and race cars use disc brakes.) This is going to give you the best simulation. It will also allow you to have different brakes with different friction amounts. Turning on Rough would also be appropriate for the brakes.