A joint connects the physics colliders of two sprites, limiting their movement relative to each other.
Joint constructors accept two sprites as input. At least one of the sprites in a joint must have a dynamic physics collider.
Every sprite has a
sprite.joints array, which contains all the joints it's currently
Do you like crafting in Legend of Zelda: Tears of the Kingdom? Then you'll love glue joints!
GlueJoint is the simplest type of joint, it just glues two sprites together. The
sprites don't have to be touching and they won't un-glue unless you remove the joint.
But wait, why use a glue joint instead of
- each sprite can have its own physics properties
- each sprite can detect collisions separately
- removing a joint doesn't remove the sprites
Joints can be visually hidden by setting
joint.visible to false or removed entirely by
Try gluing and un-gluing the stick and ball sprite in the mini example. If you want a challenge, throw the ball straight up in the air and try to stick it to the top of the stick!
By default, a
DistanceJoint is attached at the center
of each sprite that it's connected to. To shift the joint's
attachment points, edit its
Adjusting the joint's
springiness ratio changes the
amount it can stretch and compress.
0.0 = steel rod (default)
0.2 = stiff
0.4 = tight spring
0.8 = slinky
= bungee cord
You can also adjust the joints's
damping ratio to
change how quickly it loses vibrational energy.
WheelJoint connects a vehicle body to a wheel. Use wheel joints to create drive-able
Every wheel joint has a motor, which can be enabled by setting the joint's
speed to the
desired motor speed,
maxPower to a positive value, or
Disabling a wheel joint motor is like putting a car in neutral, it causes the wheel to roll freely. The joint's speed must be set to zero for the wheel to brake.
By default, wheel joints have a
maxPower of 1000,
springiness of 0.1,
damping of 0.7, and angle of attachment
angle of 90 degrees.
Try driving the car in this example! Can you make it to the end of the road? Customize the car by changing the position of its wheels and the angle at which they're attached.
HingeJoint enables one or two sprites to rotate around the same point.
To change the point of rotation edit the joint's
Hinge joints with a small
maxPower and default
speed of zero apply braking
force to resist being moved.
Try clicking around this example to drop small boxes on the seesaw. How many boxes can you put on the seesaw before it tips?
SliderJoint constrains the motion of two sprites to sliding
along a common axis, without rotation.
range determines how far apart the connected sprites can be from each other.
Changing the joint's
angle changes the direction the sprites can slide in.
By default the joint's motor is enabled with a
speed of 0, so
determines how much the joint can resist sliding.
Try dropping boxes on the scale by clicking with your mouse. How many boxes can you stack on the scale before it reaches its limit? Try changing its angle too.