Aego Русский

Distance Joint 2D

Keeps a distance between this body and the Target body. Length 0 uses the distance at start.

component physics.DistanceJoint2D
On this page

Try it

Change joint distance

The cyan dynamic body is four units from the gray static anchor. The gray line is a fixed reference, not a simulated rope.

Set Length to 2. The real distance joint pulls the body to two units from the anchor. Reset restores the four-unit distance.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene4 nodes
Anchor
Transform
position[-2, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000d00")tintColor#d1d5dbffsizeVec2[0.4, 0.4]orderint1
Bob
Transform
position[2, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000d00")tintColor#38bdf8ffsizeVec2[1.5, 1.5]orderint1
Rigid Body 2D
typeenumdynamicgravityScalefloat0fixedRotationbooltrueallowSleepboolfalseinterpolateboolfalse
Distance Joint 2D
targetNodeRefnode("d3400000000000000000000000000001")lengthfloat4
Reference line
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#4b5563ffsizeVec2[4, 0.08]
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue

Fields

NameTypeDefaultDescription
TargetNodeRefnone

The other body; both nodes need a Rigid Body 2D.

Anchor AVec2(0, 0)

Attachment point on this node, in node space.

Anchor BVec2(0, 0)

Attachment point on the Target node, in its node space.

Lengthfloat0

Rest length in units; 0 takes the distance between the anchors at start.

≥ 0
Min Lengthfloat0

Shortest allowed length. With Min and Max both 0 the joint is a rigid rod, or a spring without a lower limit when Stiffness is set.

≥ 0
Max Lengthfloat0

Longest allowed length; a rope has Min 0 and Max at the rope length.

≥ 0
Stiffnessfloat0

Spring stiffness in newtons per unit; 0 makes the length rigid within Min and Max.

≥ 0
Dampingfloat0

Spring damping; 0 never damps, higher values stop the oscillation sooner.

≥ 0
Collide Connectedboolfalse

Lets the two connected bodies collide with each other.

From a script

Reel a rope in and out by changing the joint length.

package player

import (
    "aego/input"
    "aego/math"
)

script Rope {
    var Reel float = 2

    func Update(dt float) {
        j := node.Get<DistanceJoint2D>()
        j.Length = math.Max(j.Length+input.Axis("Reel")*Reel*dt, 0.5)
        j.MaxLength = j.Length
    }
}

Script events

Scripts on a node with this component receive these events from the Physics 2D module.