fix(app+core): Phase B.3 — player cull-exempt, jump height, slope Z

Three user-reported movement fixes:

1. Player disappears when facing away: StaticMeshRenderer now accepts
   an alwaysVisibleEntityId. When a culled landblock contains the
   player entity, it is still drawn. Prevents the frustum culler from
   hiding the player character when they walk far from their spawn
   landblock.

2. Jump too high: JumpImpulse reduced from 10.0 to 3.5 (placeholder;
   retail scales by Jump skill value from the server).

3. Slope Z alignment: replaced the frame-delta slope bias with a
   foot-forward sampling approach — sample terrain Z at 1 unit ahead
   in the walk direction and use max(center, foot) as the ground Z.
   Handles multi-grade slopes where the terrain rises faster than a
   single-point sample tracks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-12 19:24:50 +02:00
parent dc0341e85a
commit 192e066182
4 changed files with 41 additions and 18 deletions

View file

@ -64,7 +64,7 @@ public sealed class PlayerMovementController
public float VerticalVelocity { get; private set; }
public bool IsAirborne { get; private set; }
public float JumpImpulse { get; set; } = 10f;
public float JumpImpulse { get; set; } = 3.5f; // placeholder; retail scales by Jump skill
public float GravityAccel { get; set; } = 20f;
public float AirControlFactor { get; set; } = 0.2f;
@ -200,19 +200,22 @@ public sealed class PlayerMovementController
}
}
// Upward bias prevents feet from sinking into the terrain surface.
// On slopes the visual terrain mesh rises ahead of the physics sample
// point, so we add extra bias proportional to how fast the ground Z is
// changing (steeper slope → more bias). Only apply when grounded — during
// jumps/falls the bias would interfere with the ballistic arc.
float slopeBias = 0f;
if (!IsAirborne)
// Foot-forward Z sampling: on slopes the visual terrain at the
// character's feet (slightly forward) can be higher than at the center.
// Sample a point ~1 unit ahead in the walk direction and use the MAX
// of center and foot Z. Only when grounded and moving.
if (!IsAirborne && (dx != 0f || dy != 0f))
{
float slopeDelta = MathF.Max(0f, newZ - _prevGroundZ);
slopeBias = MathF.Min(slopeDelta * 3f, 0.8f);
float footX = result.Position.X + forwardX * 1.0f;
float footY = result.Position.Y + forwardY * 1.0f;
var footResult = _physics.Resolve(
new Vector3(footX, footY, newZ), CellId,
Vector3.Zero, StepUpHeight);
if (footResult.IsOnGround && footResult.Position.Z > newZ)
newZ = footResult.Position.Z;
}
_prevGroundZ = newZ;
Position = new Vector3(result.Position.X, result.Position.Y, newZ + 0.15f + slopeBias);
Position = new Vector3(result.Position.X, result.Position.Y, newZ + 0.1f);
CellId = result.CellId;
// 4. Determine current motion commands.

View file

@ -1746,7 +1746,8 @@ public sealed class GameWindow : IDisposable
var camera = _cameraController.Active;
var frustum = AcDream.App.Rendering.FrustumPlanes.FromViewProjection(camera.View * camera.Projection);
_terrain?.Draw(camera, frustum);
_staticMesh?.Draw(camera, _worldState.LandblockEntries, frustum);
_staticMesh?.Draw(camera, _worldState.LandblockEntries, frustum,
alwaysVisibleEntityId: _playerMode ? _playerServerGuid : null);
// Count visible vs total for the perf overlay.
foreach (var entry in _worldState.LandblockEntries)

View file

@ -78,7 +78,8 @@ public sealed unsafe class StaticMeshRenderer : IDisposable
public void Draw(ICamera camera,
IEnumerable<(uint LandblockId, Vector3 AabbMin, Vector3 AabbMax, IReadOnlyList<WorldEntity> Entities)> landblockEntries,
FrustumPlanes? frustum = null)
FrustumPlanes? frustum = null,
uint? alwaysVisibleEntityId = null)
{
_shader.Use();
_shader.SetMatrix4("uView", camera.View);
@ -91,9 +92,19 @@ public sealed unsafe class StaticMeshRenderer : IDisposable
{
// Per-landblock frustum cull: one AABB test skips all entities in
// this landblock if it is fully outside the view frustum.
// Exception: never cull a landblock containing the player entity.
if (frustum is not null &&
!FrustumCuller.IsAabbVisible(frustum.Value, entry.AabbMin, entry.AabbMax))
continue;
{
// Check if this landblock contains the always-visible entity.
bool hasAlwaysVisible = false;
if (alwaysVisibleEntityId is not null)
{
foreach (var e in entry.Entities)
if (e.Id == alwaysVisibleEntityId.Value) { hasAlwaysVisible = true; break; }
}
if (!hasAlwaysVisible) continue;
}
foreach (var entity in entry.Entities)
{
@ -168,10 +179,18 @@ public sealed unsafe class StaticMeshRenderer : IDisposable
foreach (var entry in landblockEntries)
{
// Same per-landblock frustum cull for the translucent pass.
// Same per-landblock frustum cull + always-visible exception for pass 2.
if (frustum is not null &&
!FrustumCuller.IsAabbVisible(frustum.Value, entry.AabbMin, entry.AabbMax))
continue;
{
bool hasAlwaysVisible = false;
if (alwaysVisibleEntityId is not null)
{
foreach (var e in entry.Entities)
if (e.Id == alwaysVisibleEntityId.Value) { hasAlwaysVisible = true; break; }
}
if (!hasAlwaysVisible) continue;
}
foreach (var entity in entry.Entities)
{