← Back to list

🔗LBJT: Friction Joint8️⃣.

LibGDX Box2d Joints Tutorials.

Vladislav Shesternin · 2024-01-01 10:36 · 89 claps · 3.3 min read
#lbjt #box2d #joint #frictionjoint #libgdx
Open on Medium ↗

🔗LBJT: Friction Joint8️⃣.

LibGDX Box2d Joints Tutorials.

LBJT Application: Download for ease of study!

LBJT Application: Download for ease of study!

Friction Joint

Friction Joint

Text separators are set using chatGPT.

This article is about the Friction Joint, its settings, and how to make it work.

To make it easier to understand what is happening and how to perform practical tasks, start with the article: **🔗LBJT: Сommon in Joints 1️⃣.**

And so the… Friction Joint

Friction joint — a joint intended for connecting 2 bodies together with the ability to adjust the motion damping force and rotation damping force (usually used to simulate the absence of gravity in the body)

First, we need to set up the joint. For this, each joint has its own implementation of JointDef. You can read about this in the article: **🔗LBJT: Common in Joints 1️⃣. And now let’s talk about the FrictionJointDef**.

FrictionJointDef settings:

(Mandatory)

  • bodyA — first joint body.
  • bodyB — second joint body.
  • collideConnected — <boolean> Specifies whether bodyA should collide with bodyB.

(Optional)

  • localAnchorA — the local anchor point relative to bodyA origin.
  • localAnchorB — the local anchor point relative to bodyB origin.
  • maxForce — force is necessary to dampen the body’s motion (measured in N-m Newton-meters).
  • maxTorque — force is necessary to dampen the rotation of the body (measured in N-m Newton-meters).

FrictionJointDef settings

FrictionJointDef settings

Practice. How to create a Friction Joint?

In order for you to be able to test Joints, you need to interact with bodies, for this you need to implement MouseJoint. How to implement it is described in article *🔗LBJT: Mouse Joint 2️⃣.*

Our example will consist of a static circle (blue) and a dynamic rectangle (green) connected by FrictionJoint.

Friction Joint

Friction Joint

1️⃣Create 2 bodies: a static circle and a dynamic rectangle:

val staticCirc  = StaticBody
val dynamicRect = DynamicBody

2️⃣Create FrictionJoint:

world.createJoint(FrictionJointDef().apply {
      bodyA = staticCirc
      bodyB = dynamicRect
      collideConnected = true
}

That’s it, you can already run the program and the bodies will be connected, but there is one but, they will be connected at their anchor points, where the center of mass is indicated, if you need to change it, then you need to configure localAnchorA, localAnchorB about as I explained how to calculate anchor points in the article: **🔗LBJT: Сommon in Joints 1️⃣.**

3️⃣Configure: localAnchorA, localAnchorB:

world.createJoint(FrictionJointDef().apply {
      bodyA = staticCirc
      bodyB = dynamicRect
      collideConnected = true

      localAnchorA.set(Vector2(4.0f, 1.0f))
      localAnchorB.set(Vector2(3.5f, 2.5f))
}

Do not forget that the values are indicated in meters. About the units of measurement of meters, kilograms, seconds (MKS) is written in the [article: 🔗LBJT: Сommon in Joints 1️⃣.](https://veldan1202.medium.com/lbjt-%D1%81ommon-in-joints-1%EF%B8%8F%E2%83%A3-1677db08541d)

FrictionJoint localAnchorA | localAnchorB

FrictionJoint localAnchorA | localAnchorB

As you can see, now the body falls as if there is no connection, and this is because it is necessary to adjust the maxForce and maxTorque.

4️⃣Configure: maxForce:

maxForce — force is necessary to dampen the body’s motion (measured in N-m Newton-meters).

  • the larger the value of maxForce, the faster the body will stop, as if the force of gravity almost does not act on it.
  • the heavier the body, the larger the maxForce value should be.
world.createJoint(FrictionJointDef().apply {
      ...
      maxForce = 300f
}

FrictionJoint maxForce

FrictionJoint maxForce

5️⃣Configure: maxTorque:

maxTorque — force is necessary to dampen the rotation of the body (measured in N-m Newton-meters).

  • the larger the value of maxTorque, the faster the body will stop rotating, as if gravity almost does not act on it.
  • the heavier the body, the larger the maxTorque value should be.
world.createJoint(FrictionJointDef().apply {
      ...
      maxTorque = 300f
}

FrictionJoint maxTorque

FrictionJoint maxTorque

As you can see, the body really seems to avoid gravity, a cool effect.

It works and it’s great 😎.

[embed]

GitHub: https://github.com/Vladislav-Shesternin/LBJT 😺.

Download app LBJT ⬇️.

Main source of information 📘.

Go to Part 9️⃣.

PS. Vel_daN: Love what You DO 💚.


메타데이터
post_id
34a3f7e37e25
slug
lbjt-weld-joint8️⃣-34a3f7e37e25
url
https://medium.com/@veldan1202/lbjt-weld-joint8%EF%B8%8F%E2%83%A3-34a3f7e37e25
canonical_url
https://medium.com/@veldan1202/lbjt-weld-joint8%EF%B8%8F%E2%83%A3-34a3f7e37e25
author_url
https://medium.com/@veldan1202
status
ok
fetched_at
2026-06-28 10:39:35