The hinge joint 2D is a 2D component
that allows a sprite to rotate around a point
while being controlled by 2D rigidbody physics.
The most obvious use of a hinge joint
is to rotate a sprite around a point
to make a door.
But there are many other uses of the 2D hinge joint,
including machine parts, pendulums
and spring loaded trap doors.
A group of sprites with 2D hinge joints components
attached can work together to make a chain.
At the heart of the hinge joint 2D is the
point which the sprite will rotate around.
This is either a point in the scene
or another sprite with a 2D rigidbody attached.
This point is determined by the connected
rigidbody and the 2 anchor properties.
To connect the hinge joint 2D to the world
or a point in the scene, leave the connected rigidbody
property empty.
To connect the 2D hinge joint to another sprite
the other sprite must have a rigidbody 2D attached.
A reference to this rigidbody 2D needs to be made.
One way of doing this is to drag the
desired sprite with the rigidbody 2D attached
on to the connected rigidbody slot in the inspector.
To define the exact position of the pivot point
the properties of Anchor and
Connected Anchor need to be set.
These two properties are needed to
define a single pivot point.
The first property, Anchor, is the point the
sprite rotates around relative to the
sprite in local space.
This point does not need to be within the bounds of the sprite.
The second property, connected anchor,
is where in the scene this point is placed
and this point is relative to the connected item.
When connected to the world in the scene
these values are in world-space.
When connected to another 2D rigidbody
these values are in the connected body's local space.
When rotating around another sprite
it is important to note the Collide Connected checkbox.
With collide connected unselected
the sprite will ignore collisions with a connected sprite.
To collide with the other sprite make sure
the collide connect is selected.
The Use Motor and Use Limits are special
properties for the hinge joint.
The hinge joint can be actively powered by a motor.
When use motor is selected the hinge
joint 2D will apply torque and rotate the sprite.
Motor Speed is the target speed in degrees
per second the motor will try to reach.
Maximum Motor Force is the maximum torque
the motor can apply while attempting to reach
this target speed.
When Use Limits is selected the 2D hinge joint
will be prevented from making a full rotation.
Lower Angle is the lower end of the
rotation allowed by the limit.
Upper Angle is the upper end of the rotation
allowed by the limit.
Note the gizmo indicating the angle
limit of the joint in the scene view.
Motors and limits can be used together to
create new and interesting behaviour.
One use would be to make a spring-loaded trap door.
Use limits to prevent the trap door from
moving too far,
and use the motor to return the trap door
to it's starting position.
A series of hinge joints can be used
to make a chain.
In this example a kinematic platform
is the base sprite to which is attached
a series of sprites, each with rigidbody 2D
components to make the links.
Each link is connected to the link above
with a hinge joint 2D.
Note that collide connected is deselected.
At the bottom is the 16 tonne weight.
Unlike the links, the mass,
linear drag and angular drag have been increased
to give the weigh a proper feel in the scene.
It is worth noting that a distance joint 2D
with Max Distance Only enabled
has been added to the weight
to limit the maximum distance of the weight
from the base link, and to make the chain
perform more realistically.
For more information on the distance joint 2D
please see the information linked below.
Subtitles by the Amara.org community