fix(physics): don't fall back to no-collision resolve on transition fail
When FindTransitionalPosition fails (stuck in corner, too many steps), use the partially-resolved position instead of falling back to the simple Resolve which has no object collision. This prevents walking through objects when the transition can't find a clean path. The player now stops at corners instead of clipping through. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
08c4f2764c
commit
2ebbfc4864
1 changed files with 13 additions and 5 deletions
|
|
@ -329,18 +329,26 @@ public sealed class PhysicsEngine
|
||||||
|
|
||||||
bool ok = transition.FindTransitionalPosition(this);
|
bool ok = transition.FindTransitionalPosition(this);
|
||||||
|
|
||||||
|
var sp = transition.SpherePath;
|
||||||
|
var ci = transition.CollisionInfo;
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
var sp = transition.SpherePath;
|
|
||||||
var ci = transition.CollisionInfo;
|
|
||||||
|
|
||||||
bool onGround = ci.ContactPlaneValid
|
bool onGround = ci.ContactPlaneValid
|
||||||
|| transition.ObjectInfo.State.HasFlag(ObjectInfoState.OnWalkable);
|
|| transition.ObjectInfo.State.HasFlag(ObjectInfoState.OnWalkable);
|
||||||
|
|
||||||
return new ResolveResult(sp.CheckPos, sp.CheckCellId, onGround);
|
return new ResolveResult(sp.CheckPos, sp.CheckCellId, onGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transition failed — fall back to simple resolve.
|
// Transition failed (e.g., stuck in corner, too many steps).
|
||||||
return Resolve(currentPos, cellId, targetPos - currentPos, stepUpHeight);
|
// Use whatever position the transition reached (partial movement)
|
||||||
|
// instead of falling back to the no-collision Resolve.
|
||||||
|
// If CheckPos hasn't moved from CurPos, the player stays put —
|
||||||
|
// this is correct behavior when completely blocked.
|
||||||
|
bool partialOnGround = ci.ContactPlaneValid
|
||||||
|
|| transition.ObjectInfo.State.HasFlag(ObjectInfoState.OnWalkable)
|
||||||
|
|| isOnGround;
|
||||||
|
|
||||||
|
return new ResolveResult(sp.CheckPos, sp.CheckCellId != 0 ? sp.CheckCellId : cellId, partialOnGround);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue