< Return to Video

Joints - Unity Official Tutorials

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

more » « less
Video Language:
English
Duration:
04:28

English subtitles

Revisions