Grab buffer (squeeze early, catch on contact), elbow can't fold inward when the controller turns out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FoxyzandClaude Opus 5.5 committed 2026-10-02 21:31:14 +03:00
1 parent ca60df3d75
commit b8365ee95f
4 files changed
+48 -5

No files matched your search

+13 -2
View File
@@ -11,6 +11,10 @@ public partial class PropGrabber : Node
private const float BreakTime = 0.25f;
private const float BreakDistanceBoth = 0.4f;
private const float GripRipDistance = 0.8f;
// Grab buffer (owner: launching up a ladder leaves a short window to catch the next rung): a
// squeeze that finds nothing keeps trying while held, so you can squeeze early and catch the
// hold the moment the palm reaches it.
private const float GrabBuffer = 0.4f; // s
private const float WorldGrabRadius = 0.07f; // palm sphere for grabbing static world (ledges, bars, holds)
public const string NoGrabGroup = "no_grab"; // static bodies that can't be grabbed (the floor)
@@ -26,7 +30,8 @@ public partial class PropGrabber : Node
private readonly uint[] _grabSeq = new uint[2];
private readonly float[] _breakTimer = new float[2];
private readonly bool[] _gripPrev = new bool[2];
private readonly SoftGrab[] _easing = new SoftGrab[2]; // grabbed, being eased into the hand (no weld yet)
private readonly SoftGrab[] _easing = new SoftGrab[2];
private readonly double[] _bufferUntil = new double[2]; // grabbed, being eased into the hand (no weld yet)
private uint _grabCount;
public override void _Ready()
@@ -86,12 +91,18 @@ public partial class PropGrabber : Node
bool grip = controller.GetFloat("grip") > GripThreshold;
int other = 1 - hand;
if (grip && !_gripPrev[hand] && _held[hand] == null && _easing[hand] == null)
double now = Time.GetTicksMsec() / 1000.0;
if (grip && !_gripPrev[hand])
_bufferUntil[hand] = now + GrabBuffer;
if (grip && now <= _bufferUntil[hand] && _held[hand] == null && _easing[hand] == null)
{
PhysicsBody3D prop = FindProp(controller, hand);
RigidBody3D handBody = PhysicsHands.GetBody(controller);
if (prop != null && handBody != null)
{
_easing[hand] = SoftGrab.Begin(handBody, hand, prop); // welded once it's in the hand (_PhysicsProcess)
_bufferUntil[hand] = 0.0;
}
}
if (!grip)
_easing[hand] = null;