From c29eafab08e3889573c5da52e27bae75dd06f122 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 17:40:21 +0000 Subject: [PATCH 01/11] feat: LedgeProbeDomain.ProbeEdge takes a reach - the top is also searched that much higher, lower and further along the approach (one ray per 15 cm, the walkable hit nearest to the hand wins), so a hand jumping below a lip finds it; reach 0 probes exactly as before, with a PlayMode test Co-Authored-By: Claude Opus 5.5 --- .../Domain/Movement/LedgeProbeDomain.cs | 51 ++++++++++++++++--- .../Scripts/Services/Movement/LedgeService.cs | 8 +-- .../Gothic-Tests/PlayMode/LedgeProbeTest.cs | 16 ++++++ 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Domain/Movement/LedgeProbeDomain.cs b/Assets/Gothic-Core/Scripts/Domain/Movement/LedgeProbeDomain.cs index ce3fbb65a..135dc6aef 100644 --- a/Assets/Gothic-Core/Scripts/Domain/Movement/LedgeProbeDomain.cs +++ b/Assets/Gothic-Core/Scripts/Domain/Movement/LedgeProbeDomain.cs @@ -37,6 +37,11 @@ public class LedgeProbeDomain /// private const float _wallSearchBack = 0.4f; + /// + /// With a reach (ProbeEdge), the top is searched with one ray down per this many m further along the approach. + /// + private const float _reachStep = 0.15f; + private const float _edgeSearchStep = 0.1f; private const float _edgeSearchMax = 2f; private const float _clearance = 0.05f; @@ -117,25 +122,25 @@ public LedgeInfo ProbeAhead(Vector3 feet, Vector3 forward, LedgeBody body, Ledge /// /// A point near a lip (e.g. a hand), approached along approach. The ledge counts from baseFeetY (the floor /// the climb starts from) or, without one, from the floor at the wall's foot. + /// reach (m, 0 = right at the point): the top is also searched this much higher, lower and further along the + /// approach - a hand jumping below a lip finds it from further away. The other rules stay the same. /// public LedgeInfo ProbeEdge(Vector3 nearPoint, Vector3 approach, float? baseFeetY, LedgeBody body, - LedgeRules rules) + LedgeRules rules, float reach = 0f) { var direction = Flatten(approach); if (direction == Vector3.zero) return LedgeInfo.NoLedge; - // The top right behind the point. - var topStart = nearPoint + direction * _topInward + Vector3.up * _topSearchRange; - if (!Physics.Raycast(topStart, Vector3.down, out var topHit, _topSearchRange * 2f, body.SurfaceLayerMask, - QueryTriggerInteraction.Ignore) || !IsWalkable(topHit.normal, rules)) + // The top right behind the point (with a reach: the walkable top nearest to it). + if (!TryFindTop(nearPoint, direction, Mathf.Max(0f, reach), body, rules, out var topHit, out var inward)) return LedgeInfo.NoLedge; var topY = topHit.point.y; // A wall below the top: without one, the point is above a slope or open floor, not at a lip. var wallStart = new Vector3(nearPoint.x, topY - _lipDepth, nearPoint.z) - direction * _wallSearchBack; - if (!Physics.Raycast(wallStart, direction, out var wallHit, _wallSearchBack + _topInward * 2f, + if (!Physics.Raycast(wallStart, direction, out var wallHit, _wallSearchBack + inward + _topInward, body.SurfaceLayerMask, QueryTriggerInteraction.Ignore) || IsWalkable(wallHit.normal, rules)) return LedgeInfo.NoLedge; @@ -263,6 +268,40 @@ public LedgeInfo ProbeNpcClimb(Vector3 position, float restHeight, Vector3 direc }; } + /// + /// ProbeEdge's top: a ray down _topInward behind the point, from _topSearchRange above it to as far below. + /// With a reach, one more ray every _reachStep up to reach further along direction, each reach higher and + /// lower: the walkable hit nearest to the point wins (a crate below the hand doesn't hide the lip above it). + /// inward: how far along direction the winning ray went down. + /// + private static bool TryFindTop(Vector3 nearPoint, Vector3 direction, float reach, LedgeBody body, + LedgeRules rules, out RaycastHit topHit, out float inward) + { + topHit = default; + inward = _topInward; + var range = _topSearchRange + reach; + var bestDistanceSqr = float.MaxValue; + var steps = Mathf.CeilToInt(reach / _reachStep); + for (var i = 0; i <= steps; i++) + { + var rayInward = _topInward + Mathf.Min(i * _reachStep, reach); + var start = nearPoint + direction * rayInward + Vector3.up * range; + if (!Physics.Raycast(start, Vector3.down, out var hit, range * 2f, body.SurfaceLayerMask, + QueryTriggerInteraction.Ignore) || !IsWalkable(hit.normal, rules)) + continue; + + var distanceSqr = (hit.point - nearPoint).sqrMagnitude; + if (distanceSqr >= bestDistanceSqr) + continue; + + bestDistanceSqr = distanceSqr; + topHit = hit; + inward = rayInward; + } + + return bestDistanceSqr < float.MaxValue; + } + private static LedgeBand Classify(float height, LedgeRules rules) { if (height < rules.JumpLowHeight) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs index 49c732d5d..3cf73a82a 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs @@ -94,11 +94,13 @@ public LedgeInfo ProbeAhead(Vector3 feet, Vector3 forward, LedgeBody body) } /// - /// A ledge at a point near its lip (a hand), counted from the floor the climb starts from. + /// A ledge at a point near its lip (a hand), counted from the floor the climb starts from. reach (m): the lip + /// may also be this much further away (a hand in a jump, LedgeProbeDomain.ProbeEdge). /// - public LedgeInfo ProbeEdge(Vector3 nearPoint, Vector3 approach, float baseFeetY, LedgeBody body) + public LedgeInfo ProbeEdge(Vector3 nearPoint, Vector3 approach, float baseFeetY, LedgeBody body, + float reach = 0f) { - return _probeDomain.ProbeEdge(nearPoint, approach, baseFeetY, body, HeroRules); + return _probeDomain.ProbeEdge(nearPoint, approach, baseFeetY, body, HeroRules, reach); } /// diff --git a/Assets/Gothic-Tests/PlayMode/LedgeProbeTest.cs b/Assets/Gothic-Tests/PlayMode/LedgeProbeTest.cs index e1b340fb8..dd7251567 100644 --- a/Assets/Gothic-Tests/PlayMode/LedgeProbeTest.cs +++ b/Assets/Gothic-Tests/PlayMode/LedgeProbeTest.cs @@ -117,6 +117,22 @@ public void ProbeEdgeAtHand(float height, LedgeBand expected) Assert.That(info.StandPoint.z, Is.GreaterThan(WallZ + Body.Radius), "The stand point is on the top."); } + [Test] + public void ProbeEdgeWithReachFindsTheLipAboveAJumpingHand() + { + CreateBlock(2.5f); + var hand = new Vector3(0f, 2f, WallZ - 0.3f); + + Assert.AreEqual(LedgeBand.None, _domain.ProbeEdge(hand, Vector3.forward, 0f, Body, Rules).Band, + "Without a reach the lip is too far from the hand."); + + var info = _domain.ProbeEdge(hand, Vector3.forward, 0f, Body, Rules, 0.6f); + + Assert.AreEqual(LedgeBand.High, info.Band); + Assert.AreEqual(WallZ, info.EdgePoint.z, 0.01f); + Assert.AreEqual(2.5f, info.EdgePoint.y, 0.01f); + } + [Test] public void ProbeEdgeAtOpenFloorIsNoLedge() { From 40a9e8a9d29d906667addb6b7d95e26de92676cf Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 17:44:10 +0000 Subject: [PATCH 02/11] feat: IVrRig.MoveBody moves the player's body at once, stopped by walls (XriRig: CharacterController.Move like the leap) - in a ledge anchor's select event it runs before XRI's ClimbProvider anchors the hand, so the climb holds the hand where it arrives Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Interaction/Backends/Xri/XriRig.cs | 13 +++++++++++++ .../Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index 0f9cec68f..649184ae0 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -798,6 +798,19 @@ public void SetLedgeHandler(IVrLedgeHandler handler) _jumpProvider.SetHandler(handler); } + /// + /// Like the leap: the CharacterController moves the XR Origin with the hands at once. In a ledge anchor's + /// select event this runs before XRI's ClimbProvider.StartClimbGrab, which then anchors the hand where it + /// arrived (ClimbInteractable.OnSelectEntered raises selectEntered first, XRI 3.6.1). + /// + public void MoveBody(Vector3 motion) + { + if (_characterController != null && _characterController.enabled) + _characterController.Move(motion); + else + Root.position += motion; + } + /// /// Applied by the TeleportationProvider in its next Update(). Teleported is raised once the XRBodyTransformer /// moved the rig (same frame). The camera (not the XR Origin) ends up above the position and looks along the rotation. diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs index b8423ddb2..29e10abce 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs @@ -62,6 +62,16 @@ void SetLeapVelocity(Vector3 velocity) { } + /// + /// Moves the player's body by motion (m) at once, stopped by walls like walking (XRI: + /// CharacterController.Move). The hands move with it this frame: within a ledge grab's Grabbed event + /// (VrLedgeReach's jump reach) the climb then holds the hand where it arrives. Default: not supported, the + /// body stays. + /// + void MoveBody(Vector3 motion) + { + } + /// /// The player crouches (crouch button or the head held low). Crouched = sneaking for the scripts. /// From 56a5e88952d7a45e2f396d21213e3d33a56d995e Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 17:44:21 +0000 Subject: [PATCH 03/11] feat: ledge jump reach - in the hero's jump (HeroFallService.Phase Jumping) and 0.2 s after its landing a hand grips lips 0.6 m away: the anchor's grab box stretches to the hand, half-close tick and glow are on, the grip pulls the body until the hand sits on the lip; while falling no ledge can be grabbed like in Gothic, unless the new Immersion option ledgeGrabFalling (default off) allows it with the normal reach Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Domain/Player/VrLedgeClimber.cs | 7 +- .../Interaction/Components/VrLedgeAnchor.cs | 64 +++++++- .../Interaction/Components/VrLedgeReach.cs | 145 +++++++++++++++++- .../Services/Context/VRContextMenuService.cs | 5 + Assets/Gothic-VR/Scripts/VRConstants.cs | 4 + 5 files changed, 213 insertions(+), 12 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeClimber.cs b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeClimber.cs index 59cdf474c..44c5932b8 100644 --- a/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeClimber.cs +++ b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeClimber.cs @@ -58,16 +58,17 @@ public LedgeInfo ProbeAhead() } /// - /// The lip a hand reaches from the head, counted from the floor at baseFeetY. + /// The lip a hand reaches from the head, counted from the floor at baseFeetY. reach (m): the lip may also be + /// this much further from the hand (VrLedgeReach's jump reach). /// - public LedgeInfo ProbeAtHand(Vector3 hand, float baseFeetY) + public LedgeInfo ProbeAtHand(Vector3 hand, float baseFeetY, float reach = 0f) { var approach = hand - Rig.Head.position; approach.y = 0f; if (approach.sqrMagnitude < 0.01f) approach = Rig.Head.forward; - return _ledgeService.ProbeEdge(hand, approach, baseFeetY, Body); + return _ledgeService.ProbeEdge(hand, approach, baseFeetY, Body, reach); } /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs index 7121fc64b..06e1138f9 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs @@ -14,6 +14,8 @@ namespace Gothic.VR.Interaction.Components /// Its Rigidbody (needed by XRI's ClimbInteractable) is kinematic: it doesn't fall, and moving it reaches the /// physics scene at once, without a global Physics.SyncTransforms() (Physics.autoSyncTransforms is off). /// Local axes: x along the lip, y up, z into the wall. + /// In a jump (VrLedgeReach's jump reach) the box stretches from the lip to the hand (ReachTo), so that the hand + /// can grip from further away: GetGripOffset is then how far the body is pulled for the hand to sit on the lip. /// [RequireComponent(typeof(VrInteractable), typeof(Rigidbody))] public class VrLedgeAnchor : MonoBehaviour @@ -37,6 +39,7 @@ public class VrLedgeAnchor : MonoBehaviour private Color _glowColor = Color.white; private Rigidbody _body; + private bool _isStretched; public VrInteractable Interactable { get; private set; } @@ -48,6 +51,11 @@ public class VrLedgeAnchor : MonoBehaviour public bool IsPlaced => _collider != null && _collider.enabled; public bool IsHeld => Interactable != null && Interactable.IsHeld; + /// + /// The grab box reaches out to a hand (ReachTo) instead of only covering the lip. + /// + public bool IsStretched => _isStretched; + private void Awake() { Interactable = GetComponent(); @@ -80,9 +88,34 @@ public void Place(LedgeInfo info, Vector3 point) // The body's pose reaches the physics scene at once: the hands' grab casts see the new place this frame. _body.position = point; _body.rotation = rotation; + ResetReach(); + _collider.enabled = true; + } + + /// + /// Stretches the grab box from the lip to the point (a hand), padded by half the box's height. The anchor + /// itself stays on the lip, with its glow strip. + /// + public void ReachTo(Vector3 point) + { + var local = transform.InverseTransformPoint(point); + var half = _size / 2f; + var pad = Vector3.one * half.y; + var min = Vector3.Min(-half, local - pad); + var max = Vector3.Max(half, local + pad); + _collider.center = (min + max) / 2f; + _collider.size = max - min; + _isStretched = true; + } + + /// + /// Back to the grab box on the lip. + /// + public void ResetReach() + { _collider.size = _size; _collider.center = Vector3.zero; - _collider.enabled = true; + _isStretched = false; } public void Hide() @@ -94,7 +127,7 @@ public void Hide() } /// - /// The point is inside the grab box, grown by margin (m). + /// The point is inside the grab box on the lip (not stretched), grown by margin (m). /// public bool Contains(Vector3 point, float margin) { @@ -102,10 +135,35 @@ public bool Contains(Vector3 point, float margin) return false; var local = transform.InverseTransformPoint(point); - var half = _collider.size / 2f + Vector3.one * margin; + var half = _size / 2f + Vector3.one * margin; return Mathf.Abs(local.x) <= half.x && Mathf.Abs(local.y) <= half.y && Mathf.Abs(local.z) <= half.z; } + /// + /// The point is at most range (m) from the lip and beside the box on the lip, grown by margin (m), along it. + /// + public bool IsWithinReach(Vector3 point, float range, float margin) + { + if (!IsPlaced) + return false; + + var local = transform.InverseTransformPoint(point); + var crossSqr = local.y * local.y + local.z * local.z; + return Mathf.Abs(local.x) <= _size.x / 2f + margin && crossSqr <= range * range; + } + + /// + /// From the point (a hand) to the nearest point of the grab box on the lip: zero inside it. + /// + public Vector3 GetGripOffset(Vector3 point) + { + var local = transform.InverseTransformPoint(point); + var half = _size / 2f; + var onBox = new Vector3(Mathf.Clamp(local.x, -half.x, half.x), Mathf.Clamp(local.y, -half.y, half.y), + Mathf.Clamp(local.z, -half.z, half.z)); + return transform.TransformPoint(onBox) - point; + } + /// /// Strength 0 (hidden) to 1 (full alpha). /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs index 182fa170a..f09e32d3d 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs @@ -1,6 +1,7 @@ using System; using Gothic.Core; using Gothic.Core.Logging; +using Gothic.Core.Models.Movement; using Gothic.Core.Services.Config; using Gothic.Core.Services.Movement; using Gothic.VR.Domain.Player; @@ -18,6 +19,11 @@ namespace Gothic.VR.Interaction.Components /// climbable lip it reaches, so that the hand can grip it. What a grip does is VrLedgeClimb's part. /// Hints (Gothic.ini ledgeHints): a hand near a climbable lip half closes and ticks once, with ledgeHints Glow a /// short strip glows on the lip. Nothing is shown from afar. + /// Jump reach: in the hero's jump (HeroFallService.Phase Jumping) and _jumpReachGrace after its landing, a hand + /// reaches lips _jumpReach away. The anchor's grab box stretches to the hand (VrLedgeAnchor.ReachTo), the hints are + /// on in full, and the grip pulls the body until the hand sits on the lip (IVrRig.MoveBody) - from there the + /// climb is a normal one. While falling no ledge can be grabbed, like in Gothic (Immersion option ledgeGrabFalling + /// turns it on, with the normal reach). /// Owns whether ledge climbing is on (Climber): VrLedgeClimb and VrLedgeLocomotion work only while the reach does. /// /// Sits on the player rig. Runs before XRI's interaction manager (-105), so that the anchors are in place when the @@ -29,6 +35,7 @@ public class VrLedgeReach : MonoBehaviour { [Inject] private readonly LedgeService _ledgeService; [Inject] private readonly ConfigService _configService; + [Inject] private readonly HeroFallService _heroFallService; [Tooltip("Grab point put on a lip. One is created per hand.")] [SerializeField] private VrLedgeAnchor _anchorPrefab; @@ -44,6 +51,16 @@ public class VrLedgeReach : MonoBehaviour [SerializeField] private float _anchorKeepMargin = 0.05f; + [Tooltip("In a jump: distance in m between hand and lip from which the hand can grip it. The lip's grab box " + + "stretches to the hand, the grip pulls the body until the hand sits on the lip.")] + [SerializeField] + private float _jumpReach = 0.6f; + + [Tooltip("Seconds after a jump's landing in which the jump reach still holds: a grip at the top of a jump " + + "that landed a frame early still works.")] + [SerializeField] + private float _jumpReachGrace = 0.2f; + private readonly VrLedgeAnchor[] _anchors = new VrLedgeAnchor[2]; private readonly VrBlockHand[] _blockHands = new VrBlockHand[2]; private readonly IVrGrabber[] _grabbers = new IVrGrabber[2]; @@ -54,6 +71,11 @@ public class VrLedgeReach : MonoBehaviour private GameObject _anchorRoot; private VrLedgeHint _hint = (VrLedgeHint)VRConstants.LedgeHintsDefaultValue; private float _baseFeetY; + private bool _isGrabWhileFalling = VRConstants.LedgeGrabFallingDefaultValue == 1; + // The jump reach holds until this time (Time.time), set while jumping. + private float _jumpReachEndTime = float.MinValue; + private bool _isJumpReach; + private bool _isFallBlocked; /// /// A hand gripped an anchor. Raised within XRI's select event. @@ -132,6 +154,7 @@ private void Update() if (rig.IsGrounded && !rig.IsClimbing) _baseFeetY = _climber.Feet.y; + UpdateReachMode(rig); UpdateHand(VrHandSide.Left); UpdateHand(VrHandSide.Right); } @@ -175,13 +198,22 @@ private void UpdateHand(VrHandSide side) return; } - if (!CanReach(side)) + if (_isFallBlocked || !CanReach(side)) { HideHand(side); return; } var hand = GetHand(side).position; + if (_isJumpReach) + { + UpdateJumpReach(side, anchor, hand); + return; + } + + if (anchor.IsStretched) + anchor.ResetReach(); + if (anchor.Contains(hand, _anchorKeepMargin)) { UpdateHints(side, Vector3.Distance(hand, VrLedgeClimber.ClosestOnLip(anchor.Info, hand))); @@ -201,6 +233,103 @@ private void UpdateHand(VrHandSide side) UpdateHints(side, distance); } + /// + /// Jump reach (in a jump and shortly after its landing, not while climbing) and the fall's block (falling, + /// unless the option allows it). Logged when they change. + /// + private void UpdateReachMode(IVrRig rig) + { + var phase = _heroFallService?.Phase ?? HeroAirPhase.Grounded; + if (phase == HeroAirPhase.Jumping) + _jumpReachEndTime = Time.time + _jumpReachGrace; + else if (phase == HeroAirPhase.Falling) + _jumpReachEndTime = float.MinValue; + + var isJumpReach = !rig.IsClimbing && Time.time <= _jumpReachEndTime; + if (isJumpReach != _isJumpReach) + { + _isJumpReach = isJumpReach; + Logger.Log(isJumpReach + ? $"[Ledge] Jump reach on: lips within {_jumpReach:F2} m of a hand can be gripped." + : "[Ledge] Jump reach off.", LogCat.VR); + } + + var isFallBlocked = phase == HeroAirPhase.Falling && !_isGrabWhileFalling; + if (isFallBlocked != _isFallBlocked) + { + _isFallBlocked = isFallBlocked; + Logger.Log(isFallBlocked + ? "[Ledge] Falling: no ledge can be grabbed (Immersion option ledgeGrabFalling is off)." + : "[Ledge] Not falling any more: ledges can be grabbed again.", LogCat.VR); + } + } + + /// + /// The hand's anchor in the jump reach: kept while the hand stays within the reach of its lip (and beside it, + /// by the keep margin), else placed on the nearest lip within the reach. Its box stretches to the hand, so the + /// hand grips from there, and the hints are on in full. + /// + private void UpdateJumpReach(VrHandSide side, VrLedgeAnchor anchor, Vector3 hand) + { + if (!anchor.IsWithinReach(hand, _jumpReach, _anchorKeepMargin)) + { + var info = _climber.ProbeAtHand(hand, _baseFeetY, _jumpReach); + var point = VrLedgeClimber.ClosestOnLip(info, hand); + if (!info.IsClimbable || Vector3.Distance(hand, point) > _jumpReach) + { + HideHand(side); + return; + } + + anchor.Place(info, point); + } + + anchor.ReachTo(hand); + SetTouch(side, true); + anchor.SetGlow(_hint == VrLedgeHint.Glow ? 1f : 0f); + } + + /// + /// Raised within XRI's select event, before XRI's ClimbProvider anchors the hand: the grip of a stretched + /// anchor (jump reach) first pulls the body until the hand sits on the lip, so that the climb holds it there. + /// + private void OnAnchorGrabbed(VrLedgeAnchor anchor, VrGrabArgs args) + { + if (anchor.IsStretched) + PullOntoLip(anchor, args); + + Grabbed?.Invoke(anchor, args); + } + + /// + /// Not while another hand already climbs: the pull would tear that hand off its lip, this one grips where it + /// is (the climb follows the newest grip). + /// + private void PullOntoLip(VrLedgeAnchor anchor, VrGrabArgs args) + { + var rig = _climber.Rig; + if (args.Kind != VrGrabberKind.Hand) + return; + + if (rig.IsClimbing) + { + Logger.Log($"[Ledge] Jump reach: the {args.HandSide} hand grips the lip at {anchor.Info.EdgePoint} " + + "where it is - another hand climbs already.", LogCat.VR); + return; + } + + var hand = GetHand(args.HandSide); + var start = hand.position; + var offset = anchor.GetGripOffset(start); + if (offset.sqrMagnitude > 0.0001f) + rig.MoveBody(offset); + + anchor.ResetReach(); + var pulled = Vector3.Distance(start, hand.position); + Logger.Log($"[Ledge] Jump reach: the {args.HandSide} hand gripped the lip at {anchor.Info.EdgePoint} " + + $"from {offset.magnitude:F2} m, the body was pulled {pulled:F2} m.", LogCat.VR); + } + private bool CanReach(VrHandSide side) { var grabber = _grabbers[(int)side]; @@ -276,7 +405,7 @@ private void CreateAnchors() { var anchor = Instantiate(_anchorPrefab, _anchorRoot.transform); anchor.name = $"Ledge Anchor {(VrHandSide)i}"; - anchor.Interactable.Grabbed += args => Grabbed?.Invoke(anchor, args); + anchor.Interactable.Grabbed += args => OnAnchorGrabbed(anchor, args); anchor.Interactable.Released += args => Released?.Invoke(args); _anchors[i] = anchor; } @@ -297,14 +426,18 @@ private void FindHands() private void ReadSettings() { var gothicIni = _configService.Gothic; - if (gothicIni != null) - _hint = (VrLedgeHint)gothicIni.GetInt(VRConstants.IniNames.LedgeHints, - VRConstants.LedgeHintsDefaultValue); + if (gothicIni == null) + return; + + _hint = (VrLedgeHint)gothicIni.GetInt(VRConstants.IniNames.LedgeHints, + VRConstants.LedgeHintsDefaultValue); + _isGrabWhileFalling = gothicIni.GetInt(VRConstants.IniNames.LedgeGrabFalling, + VRConstants.LedgeGrabFallingDefaultValue) == 1; } private void OnPlayerPrefUpdated(string key, object value) { - if (key == VRConstants.IniNames.LedgeHints) + if (key is VRConstants.IniNames.LedgeHints or VRConstants.IniNames.LedgeGrabFalling) ReadSettings(); } } diff --git a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs index 4dfe92f35..98a45d6de 100644 --- a/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs +++ b/Assets/Gothic-VR/Scripts/Services/Context/VRContextMenuService.cs @@ -112,6 +112,11 @@ public void UpdateMainMenu(AbstractMenuInstance mainMenu) CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_LEDGE_HINTS", "ledgeHints", VRConstants.IniNames.LedgeHints, VRConstants.IniSectionImmersion, VRConstants.LedgeHintsDefaultValue)), + // Off = like Gothic, no ledge can be grabbed while falling (VrLedgeReach). + (CreateOptionLabel(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_LEDGE_GRAB_FALLING", "ledgeGrabFalling"), + CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_LEDGE_GRAB_FALLING", + "ledgeGrabFalling", VRConstants.IniNames.LedgeGrabFalling, VRConstants.IniSectionImmersion, + VRConstants.LedgeGrabFallingDefaultValue)), (CreateOptionLabel(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_MOVE_VIGNETTE", "moveVignette"), CreateOptionChoice(gameMenu, "MENUITEM_GOTHIC_OPT_VR_IMMERSION_MOVE_VIGNETTE", "moveVignette", VRConstants.IniNames.MoveVignette, VRConstants.IniSectionImmersion, diff --git a/Assets/Gothic-VR/Scripts/VRConstants.cs b/Assets/Gothic-VR/Scripts/VRConstants.cs index bf29692c1..82086521a 100644 --- a/Assets/Gothic-VR/Scripts/VRConstants.cs +++ b/Assets/Gothic-VR/Scripts/VRConstants.cs @@ -56,6 +56,9 @@ public static class IniNames // VrLedgeHint: 0 = off (hand half closes and ticks), 1 = glow (and a strip on the lip glows). public const string LedgeHints = "ledgeHints"; + // 0 = like Gothic, no ledge can be grabbed while falling (default), 1 = it can, with the normal reach. + public const string LedgeGrabFalling = "ledgeGrabFalling"; + // 1 = backpack in one hand + item in the other shows the item's Gothic inventory text (VRItemDetailsPopup). public const string ItemDetailsPopup = "itemDetailsPopup"; // 1 = the held backpack's opening pulls nearby world items and stores them (VRBackpackVacuum). @@ -129,6 +132,7 @@ public static class IniNames public const int HeroFallModeDefaultValue = 0; public const int HeroLandingViewDefaultValue = 0; public const int LedgeHintsDefaultValue = 1; + public const int LedgeGrabFallingDefaultValue = 0; public const int ItemDetailsPopupDefaultValue = 1; public const int BackpackVacuumDefaultValue = 1; From bb1f6390d48679d8efb5e5445af58ebd068ce892 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 17:45:11 +0000 Subject: [PATCH 04/11] docs: the ledge jump reach decision record (larger reach and pull onto the lip only in a jump, no ledge grab while falling unless the new Immersion option allows it, ladders unchanged) and its ranges, option and XRI select-order pitfall in Docs/ledge-climbing.md Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-30-ledge-air-reach.md | 23 +++++++++++++++++ Docs/ledge-climbing.md | 34 ++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Docs/adr/2026-11-30-ledge-air-reach.md diff --git a/Docs/adr/2026-11-30-ledge-air-reach.md b/Docs/adr/2026-11-30-ledge-air-reach.md new file mode 100644 index 000000000..ad5b933e1 --- /dev/null +++ b/Docs/adr/2026-11-30-ledge-air-reach.md @@ -0,0 +1,23 @@ +# ADR: Grabbing a ledge in a jump + +- Date: 2026-11-30 +- Technical details: Docs/ledge-climbing.md + +## Context + +In the play test, grabbing a ledge while jumping straight up below it was very hard: the hand had to touch the edge within a few centimetres during the short moment at the top of the jump. In the original game the hero holds the action key at a wall, the engine picks the ledge he will jump to and he climbs it. The original game also never lets the hero catch a ledge while he falls: walking off an edge or a jump that turned into a fall ends on the ground. + +## Decisions + +1. **In a jump the hands reach a ledge from about 60 cm away instead of about 20 cm.** Hands up while jumping below a ledge is enough: the edge glows (with the glow hint) and the hand half closes and vibrates as soon as it could grip. Not chosen: a key that picks the ledge for you like in Gothic, because in VR the hands already say where you want to go. +2. **Gripping from there pulls you up until the hand is on the edge, then climbing is the same as always.** You pull yourself up or fade onto the top exactly like after a normal grab. Not chosen: hanging where the hand gripped, half a metre below the edge, which would need a much longer pull than an arm can do. +3. **The larger reach lasts only for the hero's own jump and a fifth of a second after its landing.** So a grip at the top of a jump that lands a moment too early still works. On the ground nothing changes. +4. **While falling no ledge can be grabbed, like in Gothic.** A fall is walking off an edge, or a jump that took you clearly below where you jumped off. A new Immersion option ("grab while falling", off by default) allows it again, with the normal short reach - catching a ledge while falling is a VR habit some players like, but not the original game. Not chosen: the larger jump reach while falling as well, which would make every fall past a ledge end on it. +5. **Ladders stay as they are.** + +## Consequences + +- Grabbing in a jump moves you up to 60 cm at once, which feels like a short pull. Players who get motion sick can use the comfort climb, which fades anyway. +- If the second hand grips in the same moment as the first, only the first one is pulled onto its edge; the second holds where it gripped. +- Nothing new is saved. +- The new option needs its texts (label, choices, description) in the localization tables. diff --git a/Docs/ledge-climbing.md b/Docs/ledge-climbing.md index 3cd8fe987..4c56926bf 100644 --- a/Docs/ledge-climbing.md +++ b/Docs/ledge-climbing.md @@ -24,7 +24,9 @@ they block room and headroom. - `Models/Movement/*`: `LedgeRules` (values in m), `LedgeBody` (capsule + layers), `LedgeInfo` (result), `LedgeBand`. - `Domain/Movement/LedgeProbeDomain`: the probes - `ProbeAhead` (jump), `ProbeEdge` (a point near a lip, a hand), - `ProbeTop` (a teleport target, walks back to the lip). + `ProbeTop` (a teleport target, walks back to the lip). `ProbeEdge` takes a `reach` (the jump reach): the top is + then also searched that much higher, lower and further along the approach, one ray down per 15 cm, the walkable hit + nearest to the hand wins. The other checks (wall, height band, room on top) are the same; reach 0 is the old probe. - `Services/Movement/LedgeService`: reads the hero's values (Gothic's values if the scripts have none) and runs the probes. Not VR-specific: Flat jumps and NPCs can use it later. @@ -35,7 +37,21 @@ All on the XR Origin of `VR - Player XRI.prefab`: - `VrLedgeReach`: owns whether climbing is on (`Climber`: null if there is no rig or no anchor prefab - then the other two stay off as well). Moves one `VrLedgeAnchor` per empty hand along the climbable lip it reaches, plus the hints (hand half closes, haptic tick, glow strip). Lips count from the floor the player last stood on, so a jump - doesn't lower them. + doesn't lower them. Ranges by `HeroFallService.Phase` (Core, the hero's jump/fall): + - On the ground (also `Airborne`, a step down): `_touchRange` 0.2 m, with glow the anchor shows from `_glowRange` + 0.45 m; the hand grips the anchor's 0.4 x 0.12 x 0.12 m box on the lip. + - Jump reach (`Jumping`, and `_jumpReachGrace` 0.2 s after its landing so a grip at the top of a jump that landed a + frame early still works; not while climbing): `_jumpReach` 0.6 m. `ProbeAtHand` probes with that reach, the + anchor stays on the lip (its glow strip too) but its box stretches to the hand (`VrLedgeAnchor.ReachTo`), the hand + half closes, ticks and the strip glows in full. A placed anchor is kept while the hand is within the reach of its + lip and beside its box (`_anchorKeepMargin`). The grip pulls the body by `VrLedgeAnchor.GetGripOffset` (to the box + on the lip) with `IVrRig.MoveBody`, then the box shrinks back: from there it's a normal grab (`VrLedgeClimb`). + Not when another hand already climbs (it would be torn off its lip): that grip holds where it is. Logged + (`[Ledge] Jump reach ...`, LogCat VR) when the reach turns on/off and per pulled grip. + - Falling (`Falling`): no anchor, no hints - like Gothic, a falling hero catches no ledge. The Immersion option + `ledgeGrabFalling` allows it, with the ground ranges (not the jump reach). + Holding an item, swimming (grabbing off) and the comfort climb's blink (`IsSuspended`) show nothing, as before. + Ladders are separate `ClimbInteractable`s, untouched by the reach. - `VrLedgeClimber` (plain C#, `Domain/Player/`): the player's feet and body (standing height, a crouch doesn't count) and the probes from the player's view. The one place the VR side builds a `LedgeBody`. - `VrLedgeClimb`: what a grip does. Physical: XRI's `ClimbProvider` moves the rig, once pulled up 25 cm and the head @@ -53,8 +69,10 @@ anchor. Queries without a mask do see its box: leave the layer out (`NpcInitiali ## Settings -Gothic.ini, in the VR menus: `ledgeClimbMode` (Accessibility: pull up / fade) and `ledgeHints` (Immersion: off / -glow). The hand always half closes and ticks near a lip; glow adds the strip on the lip. +Gothic.ini, in the VR menus: `ledgeClimbMode` (Accessibility: pull up / fade), `ledgeHints` (Immersion: off / +glow) and `ledgeGrabFalling` (Immersion, `[GOTHIC_VR_IMMERSION]`: off / on, default off = no ledge grab while falling). +The hand always half closes and ticks near a lip; glow adds the strip on the lip. Menu texts: +`menuitem.ledgeGrabFalling.label` / `.value` / `.description` in the Gothic-UI string table. ## Pitfalls @@ -70,9 +88,15 @@ glow). The hand always half closes and ticks near a lip; glow adds the strip on - `Physics.autoSyncTransforms` is off: the anchor's Rigidbody is kinematic, and `VrLedgeAnchor.Place` sets its pose, which the physics scene sees at once. No global `Physics.SyncTransforms()` (its cost grows with every moved collider in the world, e.g. NPCs). A non-kinematic anchor would also fall once placed: `VrLedgeAnchor` warns. +- The jump reach's pull relies on XRI 3.6.1's order: `ClimbInteractable.OnSelectEntered` raises `selectEntered` + (our `Grabbed`) before `ClimbProvider.StartClimbGrab`, which anchors the hand at its world position then. With all + `allowFree*Movement` on (our settings) the provider keeps that world position, moving the anchor afterwards does + nothing - so the body moves inside the event (`IVrRig.MoveBody`, `CharacterController.Move`). On an XRI upgrade, + check that order; if it changed, the hand hangs where it gripped (the log shows the pull). - Saving while hanging stores a mid-air position. ## Tests -PlayMode `LedgeProbeTest` (bands, room, headroom, slope, hand and top probes on primitives) and +PlayMode `LedgeProbeTest` (bands, room, headroom, slope, hand probes with and without the jump reach, top probes on +primitives) and `GothicJumpProviderTest` (jump height for a rise). From 23aaf975373c44d02cf57d6df43ddbff35cc3869 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 29 Nov 2026 17:47:04 +0000 Subject: [PATCH 05/11] feat: texts of the Immersion option "Grab while falling" (ledgeGrabFalling) in all 8 languages (added through Unity MCP) Co-Authored-By: Claude Opus 5.5 --- .../Localizations/Gothic-UI Shared Data.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_cs.asset | 13 +++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_de.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_en.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_es.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_fr.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_it.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_pl.asset | 12 ++++++++++++ .../Gothic-Core/Localizations/Gothic-UI_ru.asset | 14 ++++++++++++++ 9 files changed, 111 insertions(+) diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset b/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset index 05deaaae1..c3ddf5408 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset @@ -579,6 +579,18 @@ MonoBehaviour: m_Key: menuitem.heroLandingView.description m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Key: menuitem.ledgeGrabFalling.label + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Key: menuitem.ledgeGrabFalling.value + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Key: menuitem.ledgeGrabFalling.description + m_Metadata: + m_Items: [] m_Metadata: m_Items: [] m_KeyGenerator: diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset index 8ca0925b0..a17a49b9b 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset @@ -482,6 +482,19 @@ MonoBehaviour: z\u016Fstane stranou (nekles\xE1) nebo klesne a vstane s t\u011Blem" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: "\xDAchop p\u0159i p\xE1du" + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: vyp|zap + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: "Chyt\xE1n\xED \u0159\xEDmsy p\u0159i p\xE1du. Vyp: jako v Gothicu, + bez \xFAchopu." + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset index 38b6584e1..d22f75ec6 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_de.asset @@ -608,6 +608,18 @@ MonoBehaviour: bleibt daneben (sie sinkt nicht) oder geht mit dem K\xF6rper runter und hoch" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Greifen im Fall + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: aus|an + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: 'Kanten im Fallen greifen. Aus: wie in Gothic, kein Griff.' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset index c8728bcaf..68a648463 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_en.asset @@ -620,6 +620,18 @@ MonoBehaviour: aside (it doesn''t go down) or goes down and up with the body' m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Grab While Falling + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: off|on + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: 'Catch ledges while falling. Off: like Gothic, no grab.' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset index 9194dac85..9ef17b2e2 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_es.asset @@ -471,6 +471,18 @@ MonoBehaviour: la vista se queda a un lado (no baja) o baja y sube con el cuerpo" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Agarrar al caer + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: "no|s\xED" + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: 'Agarrar bordes al caer. No: como en Gothic, sin agarre.' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset index 141239cfd..c937f11cc 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset @@ -477,6 +477,18 @@ MonoBehaviour: remonte avec le corps" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Saisir en chute + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: non|oui + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: 'Saisir les rebords en tombant. Non : comme dans Gothic.' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset index 5456bf584..6739a9e30 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_it.asset @@ -472,6 +472,18 @@ MonoBehaviour: visuale resta a lato (non scende) o scende e risale col corpo' m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Presa in caduta + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: "no|s\xEC" + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: 'Afferrare sporgenze cadendo. No: come in Gothic, nessuna presa.' + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset index bf4c32307..c5f92eb1f 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset @@ -478,6 +478,18 @@ MonoBehaviour: zostaje z boku (nie opada) albo opada i wstaje razem z cia\u0142em" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: Chwyt przy spadaniu + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: nie|tak + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: "\u0141apanie kraw\u0119dzi podczas spadania. Nie: jak w Gothicu." + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] diff --git a/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset b/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset index 54b13c3a7..804e2710b 100644 --- a/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset +++ b/Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset @@ -567,6 +567,20 @@ MonoBehaviour: \u0441 \u0442\u0435\u043B\u043E\u043C" m_Metadata: m_Items: [] + - m_Id: 199086245615902720 + m_Localized: "\u0425\u0432\u0430\u0442 \u043F\u0440\u0438 \u043F\u0430\u0434\u0435\u043D\u0438\u0438" + m_Metadata: + m_Items: [] + - m_Id: 199086245653651456 + m_Localized: "\u0432\u044B\u043A\u043B|\u0432\u043A\u043B" + m_Metadata: + m_Items: [] + - m_Id: 199086245653651457 + m_Localized: "\u0425\u0432\u0430\u0442\u0430\u0442\u044C\u0441\u044F \u0437\u0430 + \u0443\u0441\u0442\u0443\u043F\u044B \u043F\u0440\u0438 \u043F\u0430\u0434\u0435\u043D\u0438\u0438. + \u0412\u044B\u043A\u043B: \u043A\u0430\u043A \u0432 Gothic." + m_Metadata: + m_Items: [] references: version: 2 RefIds: [] From fd08d8460e835e1202fb65ba3ce19cf964d6846c Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:22:20 +0000 Subject: [PATCH 06/11] feat: LedgeService.CanCatchLedge(phase, allowWhileFalling) - the Gothic rule "a falling hero catches no ledge" (unless the player's option allows it) lives in Core, not in the VR reach Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Services/Movement/LedgeService.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs b/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs index 3cf73a82a..c6ff88c7b 100644 --- a/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs +++ b/Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs @@ -112,6 +112,16 @@ public LedgeInfo ProbeTop(Vector3 target, Vector3 from, LedgeBody body) return _probeDomain.ProbeTop(target, from, body, HeroRules); } + /// + /// Whether the hero can catch a ledge in this air phase (HeroFallService.Phase): not while falling, like in + /// Gothic - a falling hero lands. allowWhileFalling: the player's option to catch ledges anyway (VR's + /// ledgeGrabFalling). How far a hand reaches is up to the platform. + /// + public bool CanCatchLedge(HeroAirPhase phase, bool allowWhileFalling) + { + return phase != HeroAirPhase.Falling || allowWhileFalling; + } + private static LedgeRules CreateHeroRules(GuildValuesInstance values) { const int guild = (int)VmGothicEnums.Guild.GIL_HUMAN; From bb3d85f56d9a1e005751c8738d9c8b03b7425cec Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:23:19 +0000 Subject: [PATCH 07/11] refactor: VrLedgeReachMode (plain C#, Domain/Player) decides the hands' ledge reach - Normal / Jump / Blocked from HeroFallService.Phase with the 0.2 s grace and LedgeService.CanCatchLedge, logged on change; VrLedgeReach updates it before its guards (no stale flags while suspended) and hides the stretched anchors when the jump reach ends Co-Authored-By: Claude Opus 5.5 --- .../Scripts/Domain/Player/VrLedgeReachMode.cs | 73 +++++++++++++++++++ .../Interaction/Components/VrLedgeReach.cs | 71 +++++++----------- .../Interaction/Models/VrLedgeReachKind.cs | 24 ++++++ 3 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs create mode 100644 Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs diff --git a/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs new file mode 100644 index 000000000..a638c0c23 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs @@ -0,0 +1,73 @@ +using Gothic.Core.Logging; +using Gothic.Core.Models.Movement; +using Gothic.Core.Services.Movement; +using Gothic.VR.Interaction.Models; +using Logger = Gothic.Core.Logging.Logger; + +namespace Gothic.VR.Domain.Player +{ + /// + /// Which reach the hands have for ledges (VrLedgeReach), from the hero's air phase (HeroFallService.Phase): + /// Blocked while he can't catch a ledge (LedgeService.CanCatchLedge: falling, unless the player's option allows + /// it), Jump in his jump and for the grace after its landing (not while climbing), else Normal. Logged when it + /// changes. Owned by VrLedgeReach. + /// + public class VrLedgeReachMode + { + private readonly LedgeService _ledgeService; + private readonly float _jumpReach; + private readonly float _jumpGrace; + + // The jump reach holds until this time, set while jumping. + private float _jumpEndTime = float.MinValue; + + /// The hands' reach in a jump (m), for the log. + /// Seconds after a jump's landing in which the jump reach still holds. + public VrLedgeReachMode(LedgeService ledgeService, float jumpReach, float jumpGrace) + { + _ledgeService = ledgeService; + _jumpReach = jumpReach; + _jumpGrace = jumpGrace; + } + + public VrLedgeReachKind Current { get; private set; } = VrLedgeReachKind.Normal; + + /// + /// The Immersion option ledgeGrabFalling: a falling hero catches ledges, with the normal reach. + /// + public bool IsGrabWhileFalling { get; set; } + + /// + /// Once per frame, before the hands look for lips. time: Time.time. true if the mode changed. + /// + public bool Update(HeroAirPhase phase, bool isClimbing, float time) + { + if (phase == HeroAirPhase.Jumping) + _jumpEndTime = time + _jumpGrace; + else if (phase == HeroAirPhase.Falling) + _jumpEndTime = float.MinValue; + + VrLedgeReachKind mode; + if (!_ledgeService.CanCatchLedge(phase, IsGrabWhileFalling)) + mode = VrLedgeReachKind.Blocked; + else if (!isClimbing && time <= _jumpEndTime) + mode = VrLedgeReachKind.Jump; + else + mode = VrLedgeReachKind.Normal; + + if (mode == Current) + return false; + + Current = mode; + Logger.Log(mode switch + { + VrLedgeReachKind.Jump => $"[Ledge] Jump reach on: lips within {_jumpReach:F2} m of a hand can be " + + "gripped.", + VrLedgeReachKind.Blocked => "[Ledge] Falling: no ledge can be grabbed (Immersion option " + + "ledgeGrabFalling is off).", + _ => $"[Ledge] Normal reach ({phase})." + }, LogCat.VR); + return true; + } + } +} diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs index f09e32d3d..e2c7a3fc7 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs @@ -71,11 +71,7 @@ public class VrLedgeReach : MonoBehaviour private GameObject _anchorRoot; private VrLedgeHint _hint = (VrLedgeHint)VRConstants.LedgeHintsDefaultValue; private float _baseFeetY; - private bool _isGrabWhileFalling = VRConstants.LedgeGrabFallingDefaultValue == 1; - // The jump reach holds until this time (Time.time), set while jumping. - private float _jumpReachEndTime = float.MinValue; - private bool _isJumpReach; - private bool _isFallBlocked; + private VrLedgeReachMode _reachMode; /// /// A hand gripped an anchor. Raised within XRI's select event. @@ -115,6 +111,10 @@ private void Start() return; } + _reachMode = new VrLedgeReachMode(_ledgeService, _jumpReach, _jumpReachGrace) + { + IsGrabWhileFalling = VRConstants.LedgeGrabFallingDefaultValue == 1 + }; CreateAnchors(); FindHands(); ReadSettings(); @@ -143,6 +143,12 @@ private void OnDestroy() private void Update() { + // Before the guards: the mode follows the hero's jump and fall also while nothing is shown. + var rig = _climber.Rig; + var phase = _heroFallService?.Phase ?? HeroAirPhase.Grounded; + if (_reachMode.Update(phase, rig.IsClimbing, Time.time) && _reachMode.Current != VrLedgeReachKind.Jump) + HideStretchedAnchors(); + if (IsSuspended) { HideHand(VrHandSide.Left); @@ -150,11 +156,9 @@ private void Update() return; } - var rig = _climber.Rig; if (rig.IsGrounded && !rig.IsClimbing) _baseFeetY = _climber.Feet.y; - UpdateReachMode(rig); UpdateHand(VrHandSide.Left); UpdateHand(VrHandSide.Right); } @@ -198,22 +202,19 @@ private void UpdateHand(VrHandSide side) return; } - if (_isFallBlocked || !CanReach(side)) + if (_reachMode.Current == VrLedgeReachKind.Blocked || !CanReach(side)) { HideHand(side); return; } var hand = GetHand(side).position; - if (_isJumpReach) + if (_reachMode.Current == VrLedgeReachKind.Jump) { UpdateJumpReach(side, anchor, hand); return; } - if (anchor.IsStretched) - anchor.ResetReach(); - if (anchor.Contains(hand, _anchorKeepMargin)) { UpdateHints(side, Vector3.Distance(hand, VrLedgeClimber.ClosestOnLip(anchor.Info, hand))); @@ -233,37 +234,6 @@ private void UpdateHand(VrHandSide side) UpdateHints(side, distance); } - /// - /// Jump reach (in a jump and shortly after its landing, not while climbing) and the fall's block (falling, - /// unless the option allows it). Logged when they change. - /// - private void UpdateReachMode(IVrRig rig) - { - var phase = _heroFallService?.Phase ?? HeroAirPhase.Grounded; - if (phase == HeroAirPhase.Jumping) - _jumpReachEndTime = Time.time + _jumpReachGrace; - else if (phase == HeroAirPhase.Falling) - _jumpReachEndTime = float.MinValue; - - var isJumpReach = !rig.IsClimbing && Time.time <= _jumpReachEndTime; - if (isJumpReach != _isJumpReach) - { - _isJumpReach = isJumpReach; - Logger.Log(isJumpReach - ? $"[Ledge] Jump reach on: lips within {_jumpReach:F2} m of a hand can be gripped." - : "[Ledge] Jump reach off.", LogCat.VR); - } - - var isFallBlocked = phase == HeroAirPhase.Falling && !_isGrabWhileFalling; - if (isFallBlocked != _isFallBlocked) - { - _isFallBlocked = isFallBlocked; - Logger.Log(isFallBlocked - ? "[Ledge] Falling: no ledge can be grabbed (Immersion option ledgeGrabFalling is off)." - : "[Ledge] Not falling any more: ledges can be grabbed again.", LogCat.VR); - } - } - /// /// The hand's anchor in the jump reach: kept while the hand stays within the reach of its lip (and beside it, /// by the keep margin), else placed on the nearest lip within the reach. Its box stretches to the hand, so the @@ -360,6 +330,19 @@ private void SetTouch(VrHandSide side, bool isTouching) GlobalEventDispatcher.LedgeTouched.Invoke(index); } + /// + /// The jump reach ended: the anchors it stretched go, the hands place them again with the new reach. The + /// hints stay - a hand that still touches its lip doesn't tick again. + /// + private void HideStretchedAnchors() + { + foreach (var anchor in _anchors) + { + if (!anchor.IsHeld) + anchor.Hide(); + } + } + private void HideHand(VrHandSide side) { var anchor = _anchors[(int)side]; @@ -431,7 +414,7 @@ private void ReadSettings() _hint = (VrLedgeHint)gothicIni.GetInt(VRConstants.IniNames.LedgeHints, VRConstants.LedgeHintsDefaultValue); - _isGrabWhileFalling = gothicIni.GetInt(VRConstants.IniNames.LedgeGrabFalling, + _reachMode.IsGrabWhileFalling = gothicIni.GetInt(VRConstants.IniNames.LedgeGrabFalling, VRConstants.LedgeGrabFallingDefaultValue) == 1; } diff --git a/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs b/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs new file mode 100644 index 000000000..33e89ad5b --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs @@ -0,0 +1,24 @@ +namespace Gothic.VR.Interaction.Models +{ + /// + /// How far the hands reach ledges right now (VrLedgeReachMode, Docs/ledge-climbing.md). + /// + public enum VrLedgeReachKind + { + /// + /// On the ground, a step down, or falling with the Immersion option ledgeGrabFalling: a hand grips lips it + /// touches. + /// + Normal, + + /// + /// The hero's jump and shortly after its landing: a hand grips lips further away, the grip pulls the body up. + /// + Jump, + + /// + /// Falling: no ledge can be grabbed, like in Gothic. + /// + Blocked + } +} From 63ecf05fbe8e11d7b80c5946cd8d50a1387a656e Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:26:30 +0000 Subject: [PATCH 08/11] refactor: the jump reach's pull onto the lip moves into the XRI backend - VrLedgeAnchor answers the new port IVrGripOffset (how far the grip pulls, zero unless stretched), XriInteractableBridge moves the rig in the climbable's select event before XRI's ClimbProvider anchors the hand (XriRig.PullBody, CharacterController.Move; off controller = no move, warned once) and warns once when a pulled hand is off its grip a frame later; IVrRig.MoveBody is gone; the anchor shrinks its box itself when placed, hidden, gripped or let go, skips resizes under 1 cm and keeps no hand behind the wall face Co-Authored-By: Claude Opus 5.5 --- .../Backends/Xri/XriInteractableBridge.cs | 76 ++++++++++++++++ .../Interaction/Backends/Xri/XriRig.cs | 22 +++-- .../Interaction/Components/VrLedgeAnchor.cs | 90 ++++++++++++++----- .../Interaction/Components/VrLedgeReach.cs | 55 ++---------- .../Interaction/Ports/IVrGripOffset.cs | 19 ++++ .../Scripts/Interaction/Ports/IVrRig.cs | 10 --- 6 files changed, 187 insertions(+), 85 deletions(-) create mode 100644 Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriInteractableBridge.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriInteractableBridge.cs index 71de66498..6b0d018a0 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriInteractableBridge.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriInteractableBridge.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Collections.Generic; using System.Linq; using Gothic.Core.Logging; @@ -22,9 +23,21 @@ namespace Gothic.VR.Interaction.Backends.Xri /// Prefabs carry the components of both backends. The XRI interactable is disabled in the prefab and only this /// bridge enables it, if XRI is the active backend. Otherwise, it stays disabled and never looks for (or /// creates) an XRInteractionManager. + /// + /// A climbable with an IVrGripOffset next to it (a ledge anchor in the jump reach) pulls the body when a hand + /// grips it directly, before XRI's ClimbProvider holds the hand (PullToGrip). /// public class XriInteractableBridge : MonoBehaviour, IVrInteractableBackend { + // A grip offset shorter than this (m) grips where the hand is. + private const float GripMinPull = 0.01f; + + // A pulled hand this far (m) from its grip a frame later is off its hold: warned. + private const float GripPullTolerance = 0.05f; + + // Once per session for all bridges: the cause is the same each time. + private static bool _isGripPullWarned; + [Tooltip("Trigger colliders that count for hovering and grabbing by hand anyway (XRI ignores triggers). " + "E.g. the backpack's grab volume, which HVR used, as its hull alone is hard to grab.")] [SerializeField] @@ -41,6 +54,8 @@ public class XriInteractableBridge : MonoBehaviour, IVrInteractableBackend private XRBaseInteractable _xrInteractable; private VrInteractable _interactable; + // Climbables only: asked how far a hand's grip pulls the body, null for most. + private IVrGripOffset _gripOffset; private bool _isSubscribed; private float _lastHandReleaseTime = float.NegativeInfinity; private bool _isGrabEnabled = true; @@ -135,6 +150,9 @@ private void TrySubscribe() return; } + if (_xrInteractable is ClimbInteractable) + _gripOffset = GetComponent(); + _xrInteractable.hoverEntered.AddListener(OnHoverEntered); _xrInteractable.hoverExited.AddListener(OnHoverExited); _xrInteractable.selectEntered.AddListener(OnSelectEntered); @@ -340,9 +358,67 @@ private void OnSelectEntered(SelectEnterEventArgs args) _selectArgs[args.interactorObject] = grabArgs; } + if (_gripOffset != null && grabArgs.Kind == VrGrabberKind.Hand) + PullToGrip(args.interactorObject, grabArgs); + _interactable.RaiseGrabbed(grabArgs); } + /// + /// Moves the body by the climbable's grip offset (IVrGripOffset), so that the climb starts with the hand on + /// its hold. XRI 3.6.1: ClimbInteractable.OnSelectEntered raises selectEntered (this listener) before + /// ClimbProvider.StartClimbGrab, which anchors the hand at its world position then - with all + /// allowFree*Movement on, moving the anchor afterwards changes nothing. So the move happens here, within the + /// select event; CheckPulledGrip warns once if that order ever changes. Not while a hand already climbs: the + /// move would tear that hand off its hold, this one grips where it is. + /// + private void PullToGrip(IXRSelectInteractor interactor, VrGrabArgs grabArgs) + { + var rig = interactor is Component component ? component.GetComponentInParent() : null; + if (rig == null) + return; + + var hand = grabArgs.HandSide == VrHandSide.Left ? rig.LeftHand : rig.RightHand; + var start = hand.position; + var offset = _gripOffset.GetGripOffset(start); + if (offset.sqrMagnitude < GripMinPull * GripMinPull) + return; + + if (rig.IsClimbing) + { + Logger.Log($"[XRI] Grip pull: the {grabArgs.HandSide} hand grips {name} at {transform.position} " + + $"{offset.magnitude:F2} m off, where it is - another hand climbs already.", LogCat.VR); + return; + } + + rig.PullBody(offset); + var pulled = Vector3.Distance(start, hand.position); + Logger.Log($"[XRI] Grip pull: the {grabArgs.HandSide} hand gripped {name} at {transform.position} from " + + $"{offset.magnitude:F2} m, the body was pulled {pulled:F2} m.", LogCat.VR); + + if (!_isGripPullWarned && offset.magnitude > GripPullTolerance) + StartCoroutine(CheckPulledGrip(hand, start + offset)); + } + + /// + /// A frame after a pulled grip, once XRI's climb held the hand: it should be at its grip. If not, a wall + /// stopped the body, or XRI's climb no longer anchors after selectEntered (an XRI upgrade, see + /// Docs/ledge-climbing.md > Pitfalls) - then every pulled grip hangs off its hold. + /// + private IEnumerator CheckPulledGrip(Transform hand, Vector3 grip) + { + yield return null; + + var distance = Vector3.Distance(hand.position, grip); + if (_isGripPullWarned || !IsHeld || distance <= GripPullTolerance) + yield break; + + _isGripPullWarned = true; + Logger.LogWarning($"[XRI] Grip pull: the hand holding {name} is {distance:F2} m off its grip - a wall " + + "stopped the body, or XRI's ClimbProvider anchored the hand before the pull " + + "(Docs/ledge-climbing.md > Pitfalls). Warned once.", LogCat.VR); + } + private void OnSelectExited(SelectExitEventArgs args) { if (!_selectArgs.Remove(args.interactorObject, out var grabArgs)) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs index 649184ae0..42b9d914b 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriRig.cs @@ -165,6 +165,7 @@ public class XriRig : MonoBehaviour, IVrRig private IVrLedgeHandler _ledgeHandler; // SetLeapVelocity: a running jump's horizontal velocity, zero = none. private Vector3 _leapVelocity; + private bool _isPullBodyWarned; public event Action Teleported; @@ -799,16 +800,25 @@ public void SetLedgeHandler(IVrLedgeHandler handler) } /// - /// Like the leap: the CharacterController moves the XR Origin with the hands at once. In a ledge anchor's - /// select event this runs before XRI's ClimbProvider.StartClimbGrab, which then anchors the hand where it - /// arrived (ClimbInteractable.OnSelectEntered raises selectEntered first, XRI 3.6.1). + /// Moves the body by motion (m) at once, stopped by walls - like the leap, the CharacterController moves the + /// XR Origin with the hands. For a grip that pulls the body (XriInteractableBridge, IVrGripOffset). Without an + /// enabled CharacterController nothing moves (moving the origin directly would pass through walls), warned + /// once. /// - public void MoveBody(Vector3 motion) + internal void PullBody(Vector3 motion) { if (_characterController != null && _characterController.enabled) + { _characterController.Move(motion); - else - Root.position += motion; + return; + } + + if (_isPullBodyWarned) + return; + + _isPullBodyWarned = true; + Logger.LogWarning("[XRI] A grip wanted to pull the body, but the CharacterController is off: the body " + + "stays, the hand grips where it is.", LogCat.VR); } /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs index 06e1138f9..bf82c816a 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeAnchor.cs @@ -1,5 +1,7 @@ using Gothic.Core.Logging; using Gothic.Core.Models.Movement; +using Gothic.VR.Interaction.Models; +using Gothic.VR.Interaction.Ports; using UnityEngine; using Logger = Gothic.Core.Logging.Logger; @@ -15,10 +17,11 @@ namespace Gothic.VR.Interaction.Components /// physics scene at once, without a global Physics.SyncTransforms() (Physics.autoSyncTransforms is off). /// Local axes: x along the lip, y up, z into the wall. /// In a jump (VrLedgeReach's jump reach) the box stretches from the lip to the hand (ReachTo), so that the hand - /// can grip from further away: GetGripOffset is then how far the body is pulled for the hand to sit on the lip. + /// can grip from further away: GetGripOffset (IVrGripOffset) is then how far the backend pulls the body for the + /// hand to sit on the lip. The box shrinks back by itself once it's placed, hidden, gripped or let go. /// [RequireComponent(typeof(VrInteractable), typeof(Rigidbody))] - public class VrLedgeAnchor : MonoBehaviour + public class VrLedgeAnchor : MonoBehaviour, IVrGripOffset { [Tooltip("Grab box in m along the lip (x), up (y) and into the wall (z), centered on the lip.")] [SerializeField] @@ -37,9 +40,14 @@ public class VrLedgeAnchor : MonoBehaviour [Tooltip("Length in m of the glowing strip along the lip.")] [SerializeField] private float _glowLength = 0.35f; + // A hand moving less than this (m) doesn't resize the stretched box: no broadphase update per frame. + private const float ReachResizeStep = 0.01f; + private Color _glowColor = Color.white; private Rigidbody _body; private bool _isStretched; + // The point the box was last stretched to, local. + private Vector3 _reachPoint; public VrInteractable Interactable { get; private set; } @@ -51,14 +59,12 @@ public class VrLedgeAnchor : MonoBehaviour public bool IsPlaced => _collider != null && _collider.enabled; public bool IsHeld => Interactable != null && Interactable.IsHeld; - /// - /// The grab box reaches out to a hand (ReachTo) instead of only covering the lip. - /// - public bool IsStretched => _isStretched; - private void Awake() { Interactable = GetComponent(); + // Subscribed before VrLedgeReach: the box is back on the lip before a grip reaches VrLedgeClimb. + Interactable.Grabbed += OnGrabbed; + Interactable.Released += OnReleased; _body = GetComponent(); if (!_body.isKinematic) Logger.LogWarning($"[Ledge] {name}: the anchor's Rigidbody isn't kinematic, it falls once placed.", @@ -76,6 +82,15 @@ private void Awake() Hide(); } + private void OnDestroy() + { + if (Interactable == null) + return; + + Interactable.Grabbed -= OnGrabbed; + Interactable.Released -= OnReleased; + } + /// /// Puts the anchor onto the lip at point (on the lip). /// @@ -94,11 +109,15 @@ public void Place(LedgeInfo info, Vector3 point) /// /// Stretches the grab box from the lip to the point (a hand), padded by half the box's height. The anchor - /// itself stays on the lip, with its glow strip. + /// itself stays on the lip, with its glow strip. Until it's placed, hidden, gripped or let go. /// public void ReachTo(Vector3 point) { var local = transform.InverseTransformPoint(point); + if (_isStretched && (local - _reachPoint).sqrMagnitude < ReachResizeStep * ReachResizeStep) + return; + + _reachPoint = local; var half = _size / 2f; var pad = Vector3.one * half.y; var min = Vector3.Min(-half, local - pad); @@ -108,20 +127,13 @@ public void ReachTo(Vector3 point) _isStretched = true; } - /// - /// Back to the grab box on the lip. - /// - public void ResetReach() - { - _collider.size = _size; - _collider.center = Vector3.zero; - _isStretched = false; - } - public void Hide() { if (_collider != null) + { + ResetReach(); _collider.enabled = false; + } SetGlow(0f); } @@ -140,7 +152,8 @@ public bool Contains(Vector3 point, float margin) } /// - /// The point is at most range (m) from the lip and beside the box on the lip, grown by margin (m), along it. + /// The point is at most range (m) from the lip and beside the box on the lip, grown by margin (m), along it - + /// on the open side: not behind the wall's face below the lip (in the wall). /// public bool IsWithinReach(Vector3 point, float range, float margin) { @@ -148,15 +161,23 @@ public bool IsWithinReach(Vector3 point, float range, float margin) return false; var local = transform.InverseTransformPoint(point); + var half = _size / 2f; + if (local.z > half.z + margin && local.y < half.y) + return false; + var crossSqr = local.y * local.y + local.z * local.z; - return Mathf.Abs(local.x) <= _size.x / 2f + margin && crossSqr <= range * range; + return Mathf.Abs(local.x) <= half.x + margin && crossSqr <= range * range; } /// - /// From the point (a hand) to the nearest point of the grab box on the lip: zero inside it. + /// While stretched (ReachTo): from the point (a hand) to the nearest point of the grab box on the lip, zero + /// inside it. Not stretched: zero, the hand grips where it is. /// public Vector3 GetGripOffset(Vector3 point) { + if (!_isStretched) + return Vector3.zero; + var local = transform.InverseTransformPoint(point); var half = _size / 2f; var onBox = new Vector3(Mathf.Clamp(local.x, -half.x, half.x), Mathf.Clamp(local.y, -half.y, half.y), @@ -164,6 +185,33 @@ public Vector3 GetGripOffset(Vector3 point) return transform.TransformPoint(onBox) - point; } + /// + /// Within the backend's select event, after the backend pulled the body (IVrGripOffset): the hand holds the + /// lip, the box goes back onto it - the other hand can't grab the stretched box meanwhile. + /// + private void OnGrabbed(VrGrabArgs args) + { + ResetReach(); + } + + private void OnReleased(VrGrabArgs args) + { + ResetReach(); + } + + /// + /// Back to the grab box on the lip. + /// + private void ResetReach() + { + if (!_isStretched) + return; + + _collider.size = _size; + _collider.center = Vector3.zero; + _isStretched = false; + } + /// /// Strength 0 (hidden) to 1 (full alpha). /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs index e2c7a3fc7..a41fccbd2 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs @@ -19,11 +19,11 @@ namespace Gothic.VR.Interaction.Components /// climbable lip it reaches, so that the hand can grip it. What a grip does is VrLedgeClimb's part. /// Hints (Gothic.ini ledgeHints): a hand near a climbable lip half closes and ticks once, with ledgeHints Glow a /// short strip glows on the lip. Nothing is shown from afar. - /// Jump reach: in the hero's jump (HeroFallService.Phase Jumping) and _jumpReachGrace after its landing, a hand - /// reaches lips _jumpReach away. The anchor's grab box stretches to the hand (VrLedgeAnchor.ReachTo), the hints are - /// on in full, and the grip pulls the body until the hand sits on the lip (IVrRig.MoveBody) - from there the - /// climb is a normal one. While falling no ledge can be grabbed, like in Gothic (Immersion option ledgeGrabFalling - /// turns it on, with the normal reach). + /// Reach (VrLedgeReachMode): in the hero's jump (HeroFallService.Phase Jumping) and _jumpReachGrace after its + /// landing, a hand reaches lips _jumpReach away. The anchor's grab box stretches to the hand + /// (VrLedgeAnchor.ReachTo), the hints are on in full, and the backend pulls the body on the grip until the hand + /// sits on the lip (IVrGripOffset) - from there the climb is a normal one. While falling no ledge can be grabbed, + /// like in Gothic (Immersion option ledgeGrabFalling turns it on, with the normal reach). /// Owns whether ledge climbing is on (Climber): VrLedgeClimb and VrLedgeLocomotion work only while the reach does. /// /// Sits on the player rig. Runs before XRI's interaction manager (-105), so that the anchors are in place when the @@ -74,7 +74,7 @@ public class VrLedgeReach : MonoBehaviour private VrLedgeReachMode _reachMode; /// - /// A hand gripped an anchor. Raised within XRI's select event. + /// A hand gripped an anchor. Raised within the backend's select event, after a pull onto the lip. /// public event Action Grabbed; @@ -259,47 +259,6 @@ private void UpdateJumpReach(VrHandSide side, VrLedgeAnchor anchor, Vector3 hand anchor.SetGlow(_hint == VrLedgeHint.Glow ? 1f : 0f); } - /// - /// Raised within XRI's select event, before XRI's ClimbProvider anchors the hand: the grip of a stretched - /// anchor (jump reach) first pulls the body until the hand sits on the lip, so that the climb holds it there. - /// - private void OnAnchorGrabbed(VrLedgeAnchor anchor, VrGrabArgs args) - { - if (anchor.IsStretched) - PullOntoLip(anchor, args); - - Grabbed?.Invoke(anchor, args); - } - - /// - /// Not while another hand already climbs: the pull would tear that hand off its lip, this one grips where it - /// is (the climb follows the newest grip). - /// - private void PullOntoLip(VrLedgeAnchor anchor, VrGrabArgs args) - { - var rig = _climber.Rig; - if (args.Kind != VrGrabberKind.Hand) - return; - - if (rig.IsClimbing) - { - Logger.Log($"[Ledge] Jump reach: the {args.HandSide} hand grips the lip at {anchor.Info.EdgePoint} " + - "where it is - another hand climbs already.", LogCat.VR); - return; - } - - var hand = GetHand(args.HandSide); - var start = hand.position; - var offset = anchor.GetGripOffset(start); - if (offset.sqrMagnitude > 0.0001f) - rig.MoveBody(offset); - - anchor.ResetReach(); - var pulled = Vector3.Distance(start, hand.position); - Logger.Log($"[Ledge] Jump reach: the {args.HandSide} hand gripped the lip at {anchor.Info.EdgePoint} " + - $"from {offset.magnitude:F2} m, the body was pulled {pulled:F2} m.", LogCat.VR); - } - private bool CanReach(VrHandSide side) { var grabber = _grabbers[(int)side]; @@ -388,7 +347,7 @@ private void CreateAnchors() { var anchor = Instantiate(_anchorPrefab, _anchorRoot.transform); anchor.name = $"Ledge Anchor {(VrHandSide)i}"; - anchor.Interactable.Grabbed += args => OnAnchorGrabbed(anchor, args); + anchor.Interactable.Grabbed += args => Grabbed?.Invoke(anchor, args); anchor.Interactable.Released += args => Released?.Invoke(args); _anchors[i] = anchor; } diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs new file mode 100644 index 000000000..b9df24f72 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +namespace Gothic.VR.Interaction.Ports +{ + /// + /// A climbable whose grip from afar pulls the player's body (a ledge anchor in the jump reach, VrLedgeAnchor). + /// Implemented by a component next to the VrInteractable, asked by the backend when a hand grips it directly: + /// the backend moves the body by the offset, stopped by walls, before its climb holds the hand - so the climb + /// starts with the hand where it should grip. Not while another hand already climbs (the move would tear that + /// hand off its hold): that grip holds where it is. + /// + public interface IVrGripOffset + { + /// + /// From the hand (the tracked controller, world space) to where it grips. Vector3.zero: it grips where it is. + /// + Vector3 GetGripOffset(Vector3 hand); + } +} diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs index 29e10abce..b8423ddb2 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrRig.cs @@ -62,16 +62,6 @@ void SetLeapVelocity(Vector3 velocity) { } - /// - /// Moves the player's body by motion (m) at once, stopped by walls like walking (XRI: - /// CharacterController.Move). The hands move with it this frame: within a ledge grab's Grabbed event - /// (VrLedgeReach's jump reach) the climb then holds the hand where it arrives. Default: not supported, the - /// body stays. - /// - void MoveBody(Vector3 motion) - { - } - /// /// The player crouches (crouch button or the head held low). Crouched = sneaking for the scripts. /// From 782c8bb194899a3725496770e9f979a238a6830d Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:28:01 +0000 Subject: [PATCH 09/11] fix: in the jump reach a ledge yields to a ladder or item the hand touches - XRI ranks near targets by attach point, so the stretched box (ranked by its lip) won over a ladder whose transform is further away; IVrGrabber.GetTouched (XriGrabberBridge: one overlap at the near caster, mapped by the interaction manager) lets VrLedgeReach hide the hand's anchor meanwhile; and a hand within 5 cm of where the jump probe last found no lip isn't probed again Co-Authored-By: Claude Opus 5.5 --- .../Backends/Xri/XriGrabberBridge.cs | 31 +++++++ .../Interaction/Components/VrLedgeReach.cs | 85 ++++++++++++++++--- .../Scripts/Interaction/Ports/IVrGrabber.cs | 11 +++ 3 files changed, 113 insertions(+), 14 deletions(-) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriGrabberBridge.cs b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriGrabberBridge.cs index a9b539d44..4feadca56 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriGrabberBridge.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Backends/Xri/XriGrabberBridge.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Gothic.Core.Logging; using Gothic.VR.Interaction.Components; using Gothic.VR.Interaction.Models; @@ -34,6 +35,9 @@ public class XriGrabberBridge : MonoBehaviour, IVrGrabber public event Action Grabbed; public event Action Released; + // GetTouched's overlap, shared by both hands (main thread, one call at a time). + private static readonly Collider[] _touchBuffer = new Collider[16]; + private NearFarInteractor _interactor; private VrGrabberKind _heldKind = VrGrabberKind.Hand; private bool _isSubscribed; @@ -213,6 +217,33 @@ public void ForceRelease() Interactor.interactionManager.CancelInteractorSelection((IXRSelectInteractor)Interactor); } + /// + /// One overlap at the near caster, as far as a grab still counts as Hand (ResolveKind), with the caster's + /// layers and triggers. Colliders map to interactables like the caster's do (the interaction manager), so + /// the list is what the hand could take now - not only the closest one, which is all the hover shows. + /// + public void GetTouched(List results) + { + results.Clear(); + var manager = Interactor.interactionManager; + if (manager == null || !Interactor.enableNearCasting || + Interactor.nearInteractionCaster is not SphereInteractionCaster caster) + return; + + var origin = caster.effectiveCastOrigin != null ? caster.effectiveCastOrigin : Interactor.transform; + var count = Physics.OverlapSphereNonAlloc(origin.position, caster.castRadius + _nearGrabMargin, + _touchBuffer, caster.physicsLayerMask, caster.physicsTriggerInteraction); + for (var i = 0; i < count; i++) + { + if (!manager.TryGetInteractableForCollider(_touchBuffer[i], out var xrInteractable)) + continue; + + var interactable = GetInteractable(xrInteractable); + if (interactable != null && !results.Contains(interactable)) + results.Add(interactable); + } + } + /// /// Args of a selection that starts now. Remembers the kind (Hand or Distance) until the release. /// diff --git a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs index a41fccbd2..cc0e74485 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Components/VrLedgeReach.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Gothic.Core; using Gothic.Core.Logging; using Gothic.Core.Models.Movement; @@ -61,10 +62,16 @@ public class VrLedgeReach : MonoBehaviour [SerializeField] private float _jumpReachGrace = 0.2f; + // A hand this close (m) to where the jump reach's probe last found nothing isn't probed again. + private const float JumpProbeStep = 0.05f; + private readonly VrLedgeAnchor[] _anchors = new VrLedgeAnchor[2]; private readonly VrBlockHand[] _blockHands = new VrBlockHand[2]; private readonly IVrGrabber[] _grabbers = new IVrGrabber[2]; private readonly bool[] _isInTouchRange = new bool[2]; + // Per hand: where the jump reach's probe last found no lip, null = probe. + private readonly Vector3?[] _jumpProbeMisses = new Vector3?[2]; + private readonly List _touched = new(); private VrLedgeClimber _climber; private bool _isClimberChecked; @@ -146,8 +153,8 @@ private void Update() // Before the guards: the mode follows the hero's jump and fall also while nothing is shown. var rig = _climber.Rig; var phase = _heroFallService?.Phase ?? HeroAirPhase.Grounded; - if (_reachMode.Update(phase, rig.IsClimbing, Time.time) && _reachMode.Current != VrLedgeReachKind.Jump) - HideStretchedAnchors(); + if (_reachMode.Update(phase, rig.IsClimbing, Time.time)) + OnReachModeChanged(); if (IsSuspended) { @@ -241,17 +248,18 @@ private void UpdateHand(VrHandSide side) /// private void UpdateJumpReach(VrHandSide side, VrLedgeAnchor anchor, Vector3 hand) { - if (!anchor.IsWithinReach(hand, _jumpReach, _anchorKeepMargin)) + // The stretched box would win XRI's pick over a ladder or item at the hand (it's ranked by the lip, not + // by the box): the ledge yields to what the hand touches. + if (IsTouchingOther(side)) { - var info = _climber.ProbeAtHand(hand, _baseFeetY, _jumpReach); - var point = VrLedgeClimber.ClosestOnLip(info, hand); - if (!info.IsClimbable || Vector3.Distance(hand, point) > _jumpReach) - { - HideHand(side); - return; - } + HideHand(side); + return; + } - anchor.Place(info, point); + if (!anchor.IsWithinReach(hand, _jumpReach, _anchorKeepMargin) && !TryPlaceInJumpReach(side, anchor, hand)) + { + HideHand(side); + return; } anchor.ReachTo(hand); @@ -259,6 +267,50 @@ private void UpdateJumpReach(VrHandSide side, VrLedgeAnchor anchor, Vector3 hand anchor.SetGlow(_hint == VrLedgeHint.Glow ? 1f : 0f); } + /// + /// The nearest lip within the jump reach. Pre-gate: a hand that stays within JumpProbeStep of where the probe + /// last found nothing isn't probed again (up to 5 rays down plus the wall rays) - the world doesn't change + /// within a jump. + /// + private bool TryPlaceInJumpReach(VrHandSide side, VrLedgeAnchor anchor, Vector3 hand) + { + var index = (int)side; + var miss = _jumpProbeMisses[index]; + if (miss.HasValue && (hand - miss.Value).sqrMagnitude < JumpProbeStep * JumpProbeStep) + return false; + + var info = _climber.ProbeAtHand(hand, _baseFeetY, _jumpReach); + var point = VrLedgeClimber.ClosestOnLip(info, hand); + if (!info.IsClimbable || Vector3.Distance(hand, point) > _jumpReach) + { + _jumpProbeMisses[index] = hand; + return false; + } + + _jumpProbeMisses[index] = null; + anchor.Place(info, point); + return true; + } + + /// + /// The hand's direct grab range holds an interactable other than the ledge anchors. + /// + private bool IsTouchingOther(VrHandSide side) + { + var grabber = _grabbers[(int)side]; + if (grabber == null) + return false; + + grabber.GetTouched(_touched); + foreach (var interactable in _touched) + { + if (interactable != _anchors[0].Interactable && interactable != _anchors[1].Interactable) + return true; + } + + return false; + } + private bool CanReach(VrHandSide side) { var grabber = _grabbers[(int)side]; @@ -290,11 +342,16 @@ private void SetTouch(VrHandSide side, bool isTouching) } /// - /// The jump reach ended: the anchors it stretched go, the hands place them again with the new reach. The - /// hints stay - a hand that still touches its lip doesn't tick again. + /// A new jump probes afresh. When the jump reach ends, the anchors it stretched go and the hands place them + /// again with the new reach. The hints stay - a hand that still touches its lip doesn't tick again. /// - private void HideStretchedAnchors() + private void OnReachModeChanged() { + _jumpProbeMisses[0] = null; + _jumpProbeMisses[1] = null; + if (_reachMode.Current == VrLedgeReachKind.Jump) + return; + foreach (var anchor in _anchors) { if (!anchor.IsHeld) diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGrabber.cs b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGrabber.cs index 895a353e0..dfc72d455 100644 --- a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGrabber.cs +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGrabber.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Gothic.VR.Interaction.Components; using Gothic.VR.Interaction.Models; @@ -31,5 +32,15 @@ public interface IVrGrabber event Action Released; void ForceRelease(); + + /// + /// The interactables within the hand's direct grab range right now (a grab now would take one of them as + /// Kind Hand), each once. Asked per frame only while needed (VrLedgeReach in a jump). Default: none, for + /// grabbers without a direct range (sockets). + /// + void GetTouched(List results) + { + results.Clear(); + } } } From 59a6f0f401670f8e1e85073c8a035c63de30b4b6 Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:28:42 +0000 Subject: [PATCH 10/11] docs: ledge jump reach after the review - VrLedgeReachMode, the pull in the XRI backend (IVrGripOffset, XriInteractableBridge.PullToGrip, the once-only off-grip warning as XRI-upgrade guard), the ledge yielding to a touched ladder or item, the probe pre-gate and LedgeService.CanCatchLedge in Docs/ledge-climbing.md; the decision record's consequences name where the pull happens and the ladder/item rule Co-Authored-By: Claude Opus 5.5 --- Docs/adr/2026-11-30-ledge-air-reach.md | 3 +++ Docs/ledge-climbing.md | 34 +++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Docs/adr/2026-11-30-ledge-air-reach.md b/Docs/adr/2026-11-30-ledge-air-reach.md index ad5b933e1..62b3b3a18 100644 --- a/Docs/adr/2026-11-30-ledge-air-reach.md +++ b/Docs/adr/2026-11-30-ledge-air-reach.md @@ -19,5 +19,8 @@ In the play test, grabbing a ledge while jumping straight up below it was very h - Grabbing in a jump moves you up to 60 cm at once, which feels like a short pull. Players who get motion sick can use the comfort climb, which fades anyway. - If the second hand grips in the same moment as the first, only the first one is pulled onto its edge; the second holds where it gripped. +- The pull happens in the VR backend, at the moment a hand grips, before the backend's climbing takes over the hand. It depends on the order inside the XR Interaction Toolkit 3.6.1; the game warns once in the log if a pulled hand doesn't end up on the edge (e.g. after an upgrade), see Docs/ledge-climbing.md > Pitfalls. The ledge parts themselves only say how far a grip pulls. +- While a hand touches a ladder or an item in a jump, the ledge next to it can't be gripped from afar, so the ladder or item is taken. +- "A falling hero catches no ledge" is a game rule in Core (LedgeService), the 60 cm reach stays a VR matter. - Nothing new is saved. - The new option needs its texts (label, choices, description) in the localization tables. diff --git a/Docs/ledge-climbing.md b/Docs/ledge-climbing.md index 4c56926bf..a217d57c2 100644 --- a/Docs/ledge-climbing.md +++ b/Docs/ledge-climbing.md @@ -37,19 +37,28 @@ All on the XR Origin of `VR - Player XRI.prefab`: - `VrLedgeReach`: owns whether climbing is on (`Climber`: null if there is no rig or no anchor prefab - then the other two stay off as well). Moves one `VrLedgeAnchor` per empty hand along the climbable lip it reaches, plus the hints (hand half closes, haptic tick, glow strip). Lips count from the floor the player last stood on, so a jump - doesn't lower them. Ranges by `HeroFallService.Phase` (Core, the hero's jump/fall): + doesn't lower them. The ranges are `VrLedgeReachMode`'s (plain C#, `Domain/Player/`: Normal / Jump / Blocked from + `HeroFallService.Phase`, Core's hero jump/fall, updated first thing each frame; logged `[Ledge] ...`, LogCat VR, on + every change): - On the ground (also `Airborne`, a step down): `_touchRange` 0.2 m, with glow the anchor shows from `_glowRange` 0.45 m; the hand grips the anchor's 0.4 x 0.12 x 0.12 m box on the lip. - Jump reach (`Jumping`, and `_jumpReachGrace` 0.2 s after its landing so a grip at the top of a jump that landed a - frame early still works; not while climbing): `_jumpReach` 0.6 m. `ProbeAtHand` probes with that reach, the - anchor stays on the lip (its glow strip too) but its box stretches to the hand (`VrLedgeAnchor.ReachTo`), the hand + frame early still works; not while climbing): `_jumpReach` 0.6 m. `ProbeAtHand` probes with that reach (not again + while the hand stays within 5 cm of where it last found nothing), the anchor stays on the lip (its glow strip + too) but its box stretches to the hand (`VrLedgeAnchor.ReachTo`, resized only when the hand moved 1 cm), the hand half closes, ticks and the strip glows in full. A placed anchor is kept while the hand is within the reach of its - lip and beside its box (`_anchorKeepMargin`). The grip pulls the body by `VrLedgeAnchor.GetGripOffset` (to the box - on the lip) with `IVrRig.MoveBody`, then the box shrinks back: from there it's a normal grab (`VrLedgeClimb`). + lip, beside its box (`_anchorKeepMargin`) and not inside the wall. While the hand's direct grab range touches + another interactable (`IVrGrabber.GetTouched`: a ladder, an item) the hand's anchor hides: XRI ranks near + targets by their attach point, so the stretched box (ranked by its lip) could win over a ladder whose transform is + further away. The grip pulls the body onto the lip: `VrLedgeAnchor` answers `IVrGripOffset.GetGripOffset` (to its + box on the lip, zero unless stretched) and `XriInteractableBridge` moves the rig by it (`XriRig.PullBody`, + `CharacterController.Move`) before XRI's climb holds the hand - from there it's a normal grab (`VrLedgeClimb`). Not when another hand already climbs (it would be torn off its lip): that grip holds where it is. Logged - (`[Ledge] Jump reach ...`, LogCat VR) when the reach turns on/off and per pulled grip. - - Falling (`Falling`): no anchor, no hints - like Gothic, a falling hero catches no ledge. The Immersion option - `ledgeGrabFalling` allows it, with the ground ranges (not the jump reach). + `[XRI] Grip pull ...` per pulled grip. The anchor shrinks its box by itself when placed, hidden, gripped or let + go; the anchors hide when the jump reach ends and are placed again with the ground ranges. + - Falling (`Falling`, Blocked): no anchor, no hints - like Gothic, a falling hero catches no ledge + (`LedgeService.CanCatchLedge`). The Immersion option `ledgeGrabFalling` allows it, with the ground ranges (not + the jump reach). Holding an item, swimming (grabbing off) and the comfort climb's blink (`IsSuspended`) show nothing, as before. Ladders are separate `ClimbInteractable`s, untouched by the reach. - `VrLedgeClimber` (plain C#, `Domain/Player/`): the player's feet and body (standing height, a crouch doesn't count) @@ -89,10 +98,13 @@ The hand always half closes and ticks near a lip; glow adds the strip on the lip which the physics scene sees at once. No global `Physics.SyncTransforms()` (its cost grows with every moved collider in the world, e.g. NPCs). A non-kinematic anchor would also fall once placed: `VrLedgeAnchor` warns. - The jump reach's pull relies on XRI 3.6.1's order: `ClimbInteractable.OnSelectEntered` raises `selectEntered` - (our `Grabbed`) before `ClimbProvider.StartClimbGrab`, which anchors the hand at its world position then. With all + before `ClimbProvider.StartClimbGrab`, which anchors the hand at its world position then. With all `allowFree*Movement` on (our settings) the provider keeps that world position, moving the anchor afterwards does - nothing - so the body moves inside the event (`IVrRig.MoveBody`, `CharacterController.Move`). On an XRI upgrade, - check that order; if it changed, the hand hangs where it gripped (the log shows the pull). + nothing - so the backend moves the body inside the event: `XriInteractableBridge.PullToGrip`, the only place that + knows the order (components only answer `IVrGripOffset`). Deferring the move by a frame breaks the pull. If the + order changes on an XRI upgrade, the hand hangs where it gripped: a frame after a pull of more than 5 cm the bridge + checks the hand is at its grip and warns once if not (`[XRI] Grip pull: ... off its grip`; a wall that stopped + the body warns the same way). Without an enabled CharacterController the body doesn't move (warned once). - Saving while hanging stores a mid-air position. ## Tests From 676a5ad4d1b8b5fcc6043cf73c64a3fea63dd4fb Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Mon, 30 Nov 2026 00:30:13 +0000 Subject: [PATCH 11/11] chore: meta files of IVrGripOffset, VrLedgeReachKind and VrLedgeReachMode (generated by Unity on import) Co-Authored-By: Claude Opus 5.5 --- Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs.meta | 2 ++ .../Scripts/Interaction/Models/VrLedgeReachKind.cs.meta | 2 ++ .../Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs.meta | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs.meta create mode 100644 Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs.meta create mode 100644 Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs.meta diff --git a/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs.meta b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs.meta new file mode 100644 index 000000000..bb30f32f1 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeReachMode.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cda0ab3731bda27468f3abcf8a4793ec \ No newline at end of file diff --git a/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs.meta b/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs.meta new file mode 100644 index 000000000..061c5467e --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Interaction/Models/VrLedgeReachKind.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e252ca212957030449cbde2d562e6f9e \ No newline at end of file diff --git a/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs.meta b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs.meta new file mode 100644 index 000000000..824e1ce50 --- /dev/null +++ b/Assets/Gothic-VR/Scripts/Interaction/Ports/IVrGripOffset.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3d9ddeb8660d0374d8aad8b0526a0a50 \ No newline at end of file