RopeLine#
Generic rope physics, independent of what the ends are: a fixed anchor, a list of pivots where the rope wraps around geometry, and a free end. The free end follows whatever the caller drives (a character, a hook, a body); the rope bends around corners the free end sweeps past and unwraps when it swings back. Length is a hard limit: Constrain keeps a point (and its velocity) inside it, measured from the last pivot, so a wrapped rope swings about the corner. Only the geometry the caller's RopeRay reports is wrapped around. Deterministic, GL-free, no allocation per step beyond pivot changes.
public sealed class RopeLineMembers: Anchor · Constrain · End · FixedLength · FreeAllowed · FreeLength · LastFixed · Length · MaxPivots · MinFreeLength · PivotCount · Pivots · Radius · Reel · Reset · RopeLine · Sample · SetLength · Slack · Taut · Unwraps · Update · Wraps
Anchor#
public Vector3 Anchor { get; }Constrain#
public bool Constrain(ref Vector3 position, ref Vector3 velocity);Keep a body at the free end inside the rope: pulled back onto the sphere around the last fixed point, and its outward velocity removed (a rope is inelastic). Returns true when the rope is carrying load.
End#
public Vector3 End { get; }FixedLength#
public float FixedLength { get; }Rope length used up before the free span (anchor to last pivot).
FreeAllowed#
public float FreeAllowed { get; }Longest the free span may be now.
FreeLength#
public float FreeLength { get; }LastFixed#
public Vector3 LastFixed { get; }The last fixed point of the rope: the anchor, or the most recent wrap pivot.
Length#
public float Length { get; }Maximum total path length, anchor → pivots → end.
MaxPivots#
public int MaxPivots;MinFreeLength#
public float MinFreeLength;PivotCount#
public int PivotCount { get; }Pivots#
public IReadOnlyList<Vector3> Pivots { get; }Radius#
public float Radius { get; }Rope thickness; pivots stand this far (plus a margin) off the surface they wrap.
Reel#
public void Reel(float amount);Shorten (positive) or lengthen (negative) the rope, never below what the wraps need plus the minimum free span.
Reset#
public void Reset(Vector3 anchor, Vector3 end, float length);Start over from a new anchor and end with no wraps (a hook in flight, or a rope re-thrown), keeping the radius.
RopeLine#
public RopeLine(Vector3 anchor, Vector3 end, float length, float radius = .03f);Sample#
public void Sample(List<Vector3> output, int segments = 10);The path to draw: anchor, pivots, end; the free span sags in proportion to its slack. segments is the number of samples used on a sagging span.
SetLength#
public void SetLength(float length);Slack#
public float Slack { get; }Taut#
public bool Taut { get; }Unwraps#
public int Unwraps { get; }Update#
public void Update(Vector3 end, RopeRay blocked);Move the free end to end (a path the caller already validated against geometry) and update the wraps for the span it swept.
Wraps#
public int Wraps { get; }Wraps and unwraps since construction, for tests and tools.
Source#
- RopeLine.cs