Joints

In This Article:

Joints provide constraints removing degrees of freedom from a body and are used to connect pairs of bodies. Each joint has an anchor point, which is by default placed between the centers of mass of connected bodies. The properties of each connection depend on the selected joint type and its parameters. Joint parameters can be divided into two groups:

Wheel joints are used to create ray-cast vehicle wheels. It connects two rigid bodies: the first body is a frame, the second one is a wheel. There is no need to assign a shape to the wheel: ray casting is used to detect collision of the wheel with a surface. This joint has an angular motor attached.

Position of the anchor point around which the joint's motion is constrained. By default the anchor is placed between the centers of mass of connected bodies.

Linear restitution

Linear stiffness of the joint. Defines how fast it compensates for linear coordinate change between two bodies. When bodies are dragged apart, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again.

1 means that the joint is to return bodies in place throughout 1 physics tick.

0.2 means that the joint is to return bodies in place throughout 5 physics ticks.

Notice

The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Angular restitution

Angular stiffness of the joint. Defines how fast it compensates for change of the angle between two bodies. When bodies are turned relative each other, restitution controls the magnitude of force which is applied to both bodies so that their anchor points to become aligned again.

1 means that the joint is to return bodies in place throughout 1 physics tick.

0.2 means that the joint is to return bodies in place throughout 5 physics ticks.

Notice

The maximum value of 1 can lead to destabilization of physics (as too great forces are applied).

Linear softness

Linear elasticity of the joint. Defines whether linear velocities of the bodies are averaged out when the joint is stretched.

0 means that the joint is rigid. Velocities of the first and the second body are independent.

1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Angular softness

Angular elasticity of the joint. Defines whether linear velocities of the bodies are averaged out when the joint is twisted.

0 means that the joint is rigid. Velocities of the first and the second body are independent.

1 means that the joint is elastic (jelly-like). If the first body changes its velocity, velocity of the second body is equalized with it.

Max force

Maximum force that can be exerted on the joint. If this limit is exceeded, the joint breaks. The default value is inf, i.e. the joint is unbreakable.

Max torque

Maximum torque that can be exerted on the joint. If this limit is exceeded, the joint breaks. The default value is inf, i.e. the joint is unbreakable.

Number of iterations

Joints, like collisions, are calculated iteratively. This parameter specifies the number of iterations used to solve joints. Note that if this value is too low, the precision of calculations will suffer.

Springs try to keep the bodies connected with a joint at some specific distance (linear) or angle (angular). The behavior of a particular spring depends on its rigidity and damping coefficient.

Motors provide movement or rotation of bodies connected with a joint relative to each other by applying a torque (or force) to a joint's degree of freedom. There are linear and angular motors that exert a limited force to a joint, pushing or rotating connected objects.

Motors have two parameters:

Target velocity

Maximum force (or torque) that is available to reach that velocity.

This is a very simple model of real life motors. However, is it quite useful when modeling a motor, that is geared down with a gearbox before being connected to the joint. Such devices are often controlled by setting a target velocity, and can only generate a maximum amount of power to achieve that speed (which corresponds to a certain amount of force available at the joint).

To activate an angular motor perform the following steps:

Set angular velocity - target angular velocity of the motor, This value determines how fast the motor can rotate.

Vehicles are important in real-time games, therefore, they are to be described separately. There are two approaches to simulation of moving vehicles. Each approach has a corresponding joint type to connect wheels to vehicle body.

The first approach uses a suspension joint and assumes that wheels are represented as physical bodies with shapes. As each wheel has a collider shape, collisions with objects on the ground are handled correctly. For example, such car runs on a curb smoothly. This approach requires more calculations and is to be used when more accurate simulation is needed especially for step-like ground surface and wheels have a complex shape.

The second approach uses a wheel joint and assumes that the wheels are virtual. Wheels do not collide with the surface of the road. Instead, rays are cast down from the car body to detect surface unevenness. In this case steep changes of the terrain are not handled accurately. This approach is faster then the first one and provides acceptable results for smooth terrain, e.g. for racing cars simulation. However, on cross-country terrains it may not work correctly.

Both joints have a motor associated with them, which rotates the wheels and pushes the vehicle forward.