Elbow: read the hand-suggested angle nearest the current one (fixes side-switching when pointing the controller down: 45 -> 0 switches); point-down spike phase

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FoxyzandClaude Opus 5.5 committed 2026-10-02 01:48:12 +03:00
1 parent 7bc6a866eb
commit 3f912367ff
2 files changed
+30 -3

No files matched your search

+8 -1
View File
@@ -331,7 +331,14 @@ public partial class PhysicsArms : Node
handElbow -= dir * handElbow.Dot(dir);
float confidence = Mathf.Clamp(handElbow.Length() / (0.5f * radius + 1e-4f), 0f, 1f);
if (handElbow.LengthSquared() > 1e-8f)
targetAngle = Mathf.Atan2(handElbow.Dot(refB), handElbow.Dot(refN)) * PoleHandWeight * confidence;
{
// Read the suggestion as the representation NEAREST the current elbow angle:
// pointing the controller down puts it at the ±180° seam, where jitter would
// otherwise flip the clamped elbow to the other side.
float raw = Mathf.Atan2(handElbow.Dot(refB), handElbow.Dot(refN));
raw = _poleAngle[index] + Mathf.Wrap(raw - _poleAngle[index], -Mathf.Pi, Mathf.Pi);
targetAngle = raw * PoleHandWeight * confidence;
}
}
targetAngle = Mathf.Clamp(targetAngle, -PoleMaxAngle, PoleMaxAngle);
float step = (targetAngle - _poleAngle[index]) * (1f - Mathf.Exp(-delta * PoleSmoothRate));