![]() ![]() ![]() The name says it all: this parameter indicates the distance to maintain between both objects.īack in the Scene view, you can see a small green line intersecting the line connecting the two objects you can see this in the image below. The fifth parameter of the Distance Joint 2D is the one that bears its namesake: Distance. Once again, you can leave this value at (0, 0). This anchor point appears in the above image as a solid blue circle centered over Square_joint. However, when Connected Rigid Body is set, as it is now, the Connected Anchor coordinates refer to the connected rigid body’s local coordinate space. If the Connected Rigid Body field is empty, this value is in the scene’s coordinate system. The Connected Anchor parameter specifies the anchor point of the other end of the joint. In either case, moving the anchor away from (0, 0) will show that it is indeed an unfilled circle. Likewise, you will see a white square if you have the Scale tool selected. Note: The unfilled blue circle representing the joint’s first anchor point may appear filled if you currently have the Transform tool selected in the Scene view. In the Scene view, with Hexagon_Djoint selected, you can see the anchor point as an unfilled blue circle centered over Hexagon_Djoint in the image above In this case, leaving the value at (0, 0) is fine. The next parameter is Anchor, which indicates where the end point of the joint attaches to the GameObject as specified in the object’s local coordinate space. With the connection set up and Hexagon_Djoint still selected, you should now see the two objects connected by the joint in the Scene view as follows: You want to connect Hexagon_Djoint to Square_Djoint in this case, so drag Square_Djoint to the Connected Rigid Body field: ![]() If you leave this field empty, Unity will simply connect the other end of the joint to a fixed point in the scene. While one end of the distance joint always remains connected to the object that contains the component, you can use this field to pass a reference to an object for the other end of the joint’s connection. The second parameter is Connected Rigid Body. In this case, you don’t want this to happen, so leave it unchecked. This determines whether or not the two objects connected by the joint can collide with each other. The Distance Joint 2D’s first parameter is Collide Connected. Turn your attention back the component in the Inspector. The rocking behavior is the actual joint behavior, but what’s the deal with the initial jolt of energy? This is actual expected behavior and you’ll learn about it soon. Right away, you’ll notice that the Hexagon flies across the screen until it stops near the origin point, then begins to rock back and forth on the joint. Run the scene, keeping your eye on the Hexagon. You’ll notice that once you have the component attached to the Hexagon that a green line extends from the Hexagon to the center of the screen. Select Hexagon_Djoint in the Hierarchy and add a Distance Joint 2D Component to it, as shown below:Īs you can see in the following image, this new component has several parameters that you can adjust to produce the best result for your game:įear not - you’ll soon learn what all these these parameters do and how you can adjust them. ![]() You’ll test this out on the red square and blue hexagon in the upper left of the scene. The first joint you’ll add – the Distance Joint 2D – has a very basic goal: to keep two objects separated by a constant distance. It’s time to get these objects working together with joints! Distance Joint 2D For best results, put your Game view in Free Aspect mode and adjust its size in the Unity GUI until the objects and labels appear similar to the above image. Note: While the labels in this scene are in fixed positions, the movement of the objects is based on the size of your Game view. ![]()
0 Comments
Leave a Reply. |