🔗LBJT: Wheel Joint 6️⃣.

LibGDX Box2d Joints Tutorials.

Vladislav Shesternin
4 min readDec 30, 2023
LBJT Application: Download for ease of study!
Wheel Joint

Text separators are set using chatGPT.

This article is about the Wheel 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… Wheel Joint

Wheel joint — a joint designed to connect two bodies together and interact between them as a wheel and a shock absorber, usually used to create a vehicle suspension.

Wheel joint — it’s like a 3-in-1 joint because it:

  1. Has an axis like Prismatic Joint.
  2. Rotates and has a motor for rotation as an Revolute Joint.
  3. Has elasticity settings are like Distance Joint.

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 WheelJointDef.

WheelJointDef 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.
  • localAxisA — the angle of the axis relative to the bodyA.
  • motorSpeed — revolutions per second (radians per second).
  • maxMotorTorque — rotation force, the greater the force, the faster the motor will gain the revolutions specified in motorSpeed (measured in N-m. Newton meter).
  • enableMotor — flag to enable the motor (default false).
  • frequencyHz — affects the elasticity of the joint between bodyA and bodyB.

Value < 1: With values less than 1, such as 0.5 or 0.7, the joint will be strongly stretched, resembling a soft spring.

Value > 1: With values greater than 1, such as 2, 5, or 10, the joint will stretch very little or not at all, similar to a stiff spring.

  • dampingRatio — suppresses vibrations and takes values from 0 to 1.

0: does not suppress.

1: almost absolute suppression.

WheelJointDef settings

Practice. How to create a Wheel 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️⃣.

To better understand the test, turn off gravity.

val gravity = Vector2(0f, 0f)
val world = World(GRAVITY)

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

Wheel Joint

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

val staticRect  = StaticBody
val dynamicCirc = DynamicBody

2️⃣Create WheelJoint:

world.createJoint(WheelJointDef().apply {
bodyA = staticRect
bodyB = dynamicCirc
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 specified, to fix this, you need to configure localAnchorA, localAnchorB about how I explained how to calculate anchor points in the article: 🔗LBJT: Сommon in Joints 1️⃣.

3️⃣Configure: localAnchorA, localAnchorB:

world.createJoint(WheelJointDef().apply {
bodyA = staticRect
bodyB = dynamicCirc
collideConnected = true

localAnchorA.set(Vector2(2.5f, -10.0f))
localAnchorB.set(Vector2(2.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️⃣.

4️⃣Configure: localAxisA:

About how I explained how to configure localAxisA in the article: 🔗LBJT: Prismatic Joint 5️⃣.

5️⃣Configure: motor:

About how I explained how to configure motor in the article: 🔗LBJT: Revolute Joint 4️⃣.

6️⃣Configure: elasticity:

About how I explained how to configure elasticity in the article: 🔗LBJT: Distance Joint3️⃣.

If you read these 3 articles, now you can configure Wheel Joint:

Wheel Join

Wheel Join — is great for creating a vehicle suspension, if it weren’t for it we would have to implement many bodies and at least 3 connections (Prismatic, Revolute, Distance) — Joint and so we can just adjust the Wheel Join, it’s easier and saves resources.

It works and it’s great 😎.

PS. Vel_daN: Love what You DO 💚.

--

--

Vladislav Shesternin
Vladislav Shesternin

Written by Vladislav Shesternin

LibGDX | Android Developer | Enthusiast.

No responses yet