To create a WheelJoint, you must first define its properties using WheelJointDef. A wheel joint provides suspension, allowing bodyB to rotate freely around an anchor while translating along a specific axis on bodyA. It supports an optional spring, translation limits, and a motor.
Configuration Properties
| Property | Type | Description |
|---|
bodyA | Body | The first body (the base/chassis). |
bodyB | Body | The second body (the wheel). |
localAnchorA | Vector2 | The anchor point on bodyA in local coordinates. Defaults to (0, 0). |
localAnchorB | Vector2 | The anchor point on bodyB in local coordinates. Defaults to (0, 0). |
localAxisA | Vector2 | The suspension axis in bodyA's local coordinates. Defaults to (0, 1). |
enableSpring | bool | Whether the suspension spring is enabled. Defaults to true. |
hertz | double | The spring stiffness in hertz. |
dampingRatio | double | The spring damping ratio (non-dimensional). |
enableLimit | bool | Whether the translation limit is enabled. Defaults to false. |
lowerTranslation | double | The lower translation limit in meters. |
upperTranslation | double | The upper translation limit in meters. |
enableMotor | bool | Whether the motor is enabled. Defaults to false. |
maxMotorTorque | double | The maximum motor torque in Newton-meters. |
motorSpeed | double | The motor speed in radians per second. |
collideConnected | bool | Whether the two bodies should collide. |
userData | dynamic | User data associated with the joint. |
final wheelDef = WheelJointDef(
bodyA: chassisBody,
bodyB: wheelBody,
localAnchorA: Vector2(0, -1),
localAnchorB: Vector2.zero(),
localAxisA: Vector2(0, 1),
enableSpring: true,
hertz: 5.0,
dampingRatio: 0.7,
enableMotor: true,
motorSpeed: 10.0,
maxMotorTorque: 20.0,
);