Distance Joint 2D
Keeps a distance between this body and the Target body. Length 0 uses the distance at start.
component physics.DistanceJoint2D
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.
Scene4 nodes
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Target | NodeRef | none | The other body; both nodes need a Rigid Body 2D. |
| Anchor A | Vec2 | (0, 0) | Attachment point on this node, in node space. |
| Anchor B | Vec2 | (0, 0) | Attachment point on the Target node, in its node space. |
| Length | float | 0 | Rest length in units; 0 takes the distance between the anchors at start. ≥ 0 |
| Min Length | float | 0 | 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 Length | float | 0 | Longest allowed length; a rope has Min 0 and Max at the rope length. ≥ 0 |
| Stiffness | float | 0 | Spring stiffness in newtons per unit; 0 makes the length rigid within Min and Max. ≥ 0 |
| Damping | float | 0 | Spring damping; 0 never damps, higher values stop the oscillation sooner. ≥ 0 |
| Collide Connected | bool | false | 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.
OnCollisionEnter— Runs after the physics step in which this body started touching other.OnCollisionExit— Runs when the bodies stop touching, including when one of them is destroyed or disabled. Contact.Point is the last known point.OnCollisionStay— Runs after every later physics step while the bodies keep touching. It costs nothing when no script declares it.OnTriggerEnter— Runs when other's collider entered a trigger of this body, or this body entered other's trigger.OnTriggerExit— Runs when the overlap with a trigger ends.
Related guides
- Components These components make a node part of the simulation.
- Physics 2D Aego simulates 2D rigid bodies with its own solver.