RopeChain#
A hanging rope or cable as a chain of particles (position-based Verlet): both ends pinned, a fixed total length, gravity, collision through the caller's RopeContact, and friction where it rests on something. Where RopeLine is a taut line that wraps corners (a grapple), this one sags and drapes (wires over pipes, a cable off a trolley). Each end can also leave along a direction (out of a wall socket), which pins the next particle one link along it. Deterministic for the same inputs; no allocation per step. Grab holds one particle where the caller drags it; letting go keeps the motion it had, so a rope can be thrown.
public sealed class RopeChainMembers: Damping · Friction · Grab · Gravity · Iterations · Length · Link · Motion · Nearest · Points · Radius · Release · RopeChain · Smooth · Step
Damping#
public float Damping { get; set; }Initial value: .01f
Fraction of velocity lost per step in air (0 none).
Friction#
public float Friction { get; set; }Initial value: .6f
Fraction of sliding velocity lost per step while touching (0 ice, 1 sticks).
Grab#
public void Grab(int index, Vector3 target);Holds particle index at target until Release; pinned ends cannot be grabbed.
Gravity#
public Vector3 Gravity { get; set; }Initial value: new(0, -9.81f, 0)
Iterations#
public int Iterations { get; set; }Initial value: 40
Length#
public float Length { get; }Link#
public float Link { get; }Rest length of one link.
Motion#
public float Motion { get; }Largest distance any particle moved in the last Step, to tell when the rope has come to rest.
Nearest#
public int Nearest(Vector3 origin, Vector3 direction, float reach);The free particle nearest a ray (for picking a rope to drag), or -1 when none is within reach.
Points#
public IReadOnlyList<Vector3> Points { get; }Radius#
public float Radius { get; }Release#
public void Release();RopeChain#
public RopeChain(Vector3 start, Vector3 end, float length, int links, float radius = .01f, Vector3? startDirection = null, Vector3? endDirection = null);A rope of length from start to end in links links, starting straight (so it never starts inside what it will hang over) and falling into its sag. A direction pins the particle after (before) the end one link along it.
Smooth#
public void Smooth(List<Vector3> output, int subdivisions = 3);The rope's path with each link split by a Catmull-Rom curve into subdivisions pieces, for drawing.
Step#
public void Step(float dt, RopeContact? contact = null);Advances the rope by dt seconds (keep it at or below 1/60).
Source#
- RopeChain.cs