Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI Shared Data.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_cs.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_de.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_en.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_es.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_fr.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_it.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
12 changes: 12 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_pl.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
14 changes: 14 additions & 0 deletions Assets/Gothic-Core/Localizations/Gothic-UI_ru.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
51 changes: 45 additions & 6 deletions Assets/Gothic-Core/Scripts/Domain/Movement/LedgeProbeDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public class LedgeProbeDomain
/// </summary>
private const float _wallSearchBack = 0.4f;

/// <summary>
/// With a reach (ProbeEdge), the top is searched with one ray down per this many m further along the approach.
/// </summary>
private const float _reachStep = 0.15f;

private const float _edgeSearchStep = 0.1f;
private const float _edgeSearchMax = 2f;
private const float _clearance = 0.05f;
Expand Down Expand Up @@ -117,25 +122,25 @@ public LedgeInfo ProbeAhead(Vector3 feet, Vector3 forward, LedgeBody body, Ledge
/// <summary>
/// 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.
/// </summary>
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;

Expand Down Expand Up @@ -263,6 +268,40 @@ public LedgeInfo ProbeNpcClimb(Vector3 position, float restHeight, Vector3 direc
};
}

/// <summary>
/// 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.
/// </summary>
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)
Expand Down
18 changes: 15 additions & 3 deletions Assets/Gothic-Core/Scripts/Services/Movement/LedgeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public LedgeInfo ProbeAhead(Vector3 feet, Vector3 forward, LedgeBody body)
}

/// <summary>
/// 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).
/// </summary>
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);
}

/// <summary>
Expand All @@ -110,6 +112,16 @@ public LedgeInfo ProbeTop(Vector3 target, Vector3 from, LedgeBody body)
return _probeDomain.ProbeTop(target, from, body, HeroRules);
}

/// <summary>
/// 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.
/// </summary>
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;
Expand Down
16 changes: 16 additions & 0 deletions Assets/Gothic-Tests/PlayMode/LedgeProbeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 4 additions & 3 deletions Assets/Gothic-VR/Scripts/Domain/Player/VrLedgeClimber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ public LedgeInfo ProbeAhead()
}

/// <summary>
/// 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).
/// </summary>
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);
}

/// <summary>
Expand Down
Loading