-
Let's look at the basic joints in Unity.
-
In this example we have fixed joints
-
and spring joints.
-
This example forms a basic wrecking ball
-
that does this.
-
Firstly the fixed joint. Fixed joints
-
work in a similar way to parenting objects
-
in the hierarchy.
-
The joint simply locks a game object
-
to the point in the world, or to a
-
connected rigidbody.
-
In this example we simply have placed the
-
first capsule in the chain up near
-
the ceiling and attached a fixed joint.
-
This locks it in place.
-
The other parameters of this fixed joint
-
are Break Force and Break Torque.
-
This is the minimum amount of force required
-
to break the joint.
-
When the joint is broken the game object
-
can once again move freely.
-
The other capsules in the chain have
-
spring joints. Spring joints work on the
-
principle that the game object is trying
-
to reach a target position. The target
-
position that it's trying to reach is the
-
position that it's set to in the scene view
-
and any rigid bodies that are attached to it
-
will pull it away from this position
-
on an invisible spring attached
-
to the anchor point.
-
If the spring joint has a connected rigidbody
-
then the target point that the spring
-
is trying to reach is relative to that
-
game object rather than to world space.
-
So for example, the second capsule here
-
is trying to reach capsule 1, and capsule 3
-
is trying to reach capsule 2.
-
As these move they will no longer be heading
-
towards the original positions, rather
-
they will be heading towards the anchor
-
point of wherever those capsules happen to be.
-
The anchor is the pivot point of the joint.
-
You should consider it as where the spring is
-
attached to the game object.
-
This is shown in the scene view by
-
an orange dot or box.
-
The spring parameter is a measure of how
-
strong the spring is. The higher the
-
value the tighter or stronger the
-
spring becomes. The damper parameter
-
is how much the joint will slow down
-
under motion. The higher the number, the
-
less the spring will overshoot.
-
The min and max distances are for setting
-
up a sort of dead zone for where the
-
spring isn't active. They effectively restrict
-
the length of the spring.
-
Similar to the fixed joint, the spring
-
also has a break force and a break torque,
-
which you can set to a certain amount in order
-
to find the minimum force required to
-
break that joint.
-
Finally, Hinge Joints.
-
Hinge joints are ideal for things like
-
doors and share some properties with
-
spring joints. The axis of the hinge
-
is the one that it rotates around.
-
In this example our physics door
-
has the hinge joint attached. The anchor
-
is set to 1 in the X axis,
-
which moves it from it's center to it's edge.
-
Again the joint is represented in
-
orange in Unity and you can see a small line
-
showing you where the hinge is currently located.
-
The axis then allows us to specify
-
around which axis the hinge will pivot.
-
We've set this to the Y axis so it will
-
react like a real hinge with a simple script
-
we're applying a force to the door
-
when we click on it, which pushes it
-
backwards in it's Z axis
-
using the shortcut minus transform.forward.
-
In the Add Force lesson you may have seen
-
that this fires the door straight out of the frame.
-
But now that we have a hinge,
-
when we apply the force to the door
-
it simply pivots around that point.
-
and no matter how many times we add force
-
to it, it doesn't break.
-
In a similar manner to our spring joint
-
we can apply spring-like characterises
-
by using the Use Spring checkbox
-
and using the values underneath the spring settings.
-
The other differences between hinge joints
-
and spring joints are motors and limits.
-
Motors are for introducing a velocity
-
to your joint, for example a revolving door.
-
The Target Velocity is the velocity the
-
joint is trying to rotate at and the
-
force is used to try and attain that velocity.
-
If Free Spin is checked then the force will
-
only be used to try and accelerate
-
the joint and not to decelerate it.
-
Limits can be used if you wish to constrain
-
the motion of your joint, like with the
-
normal door. The minimum and maximum
-
are the angles between which the joint
-
can move. Min and Max Bounce are the amount
-
by which the joint will bounce when it reaches
-
one of it's limits. And similar to our
-
spring joint, yet again we have break
-
forces and torques.
-
For example, if we add in a reasonably low
-
number into the break force property,
-
we can break the door off of the hinge
-
when adding a force. You should note that
-
when doing this the door doesn't fly directly
-
backwards but is instead pulled away from it's hinge.