feat(cut5b-1): equal-start jackals, ai scavenging, naturalized aim, ots camera & interpolation
This commit is contained in:
parent
cdce8cd843
commit
1eb37e328a
12 changed files with 1548 additions and 225 deletions
160
client/Main.cs
160
client/Main.cs
|
|
@ -28,7 +28,8 @@ public partial class Main : Node3D
|
|||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(5f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _smoothedShoulderY;
|
||||
private string? _lastCamChassisId;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
|
@ -161,8 +162,8 @@ public partial class Main : Node3D
|
|||
InteractPickup: false,
|
||||
Brake: false);
|
||||
|
||||
_arena.Sync(session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_hud.Sync(session);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +192,7 @@ public partial class Main : Node3D
|
|||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = _mapKind == ArenaMapKind.Sion ? Mathf.DegToRad(5f) : Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
_lastCamChassisId = null;
|
||||
_camera.Far = _mapKind == ArenaMapKind.Sion ? 4200f : 1800f;
|
||||
ApplyEnvironmentForMap(_mapKind);
|
||||
|
||||
|
|
@ -200,8 +201,8 @@ public partial class Main : Node3D
|
|||
_terrain.Visible = false;
|
||||
_sionMap.Visible = true;
|
||||
_sionMap.EnsureBuilt(_session.State.SionMap!, _session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
}
|
||||
else
|
||||
|
|
@ -210,8 +211,8 @@ public partial class Main : Node3D
|
|||
_terrain.Visible = true;
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f);
|
||||
UpdateCamera(1f);
|
||||
_arena.Sync(_session, _elapsedSeconds, 0f, 1f);
|
||||
UpdateCamera(1f, 1f);
|
||||
_terrain.UpdateTileLod(_camera.GlobalPosition);
|
||||
}
|
||||
|
||||
|
|
@ -337,6 +338,8 @@ public partial class Main : Node3D
|
|||
return;
|
||||
}
|
||||
|
||||
float alpha = Math.Clamp((float)Engine.GetPhysicsInterpolationFraction(), 0f, 1f);
|
||||
|
||||
if (_perfTargetFrames > 0)
|
||||
{
|
||||
double toMs = 1000.0 / Stopwatch.Frequency;
|
||||
|
|
@ -346,13 +349,13 @@ public partial class Main : Node3D
|
|||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
long tt1 = Stopwatch.GetTimestamp();
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
long ta1 = Stopwatch.GetTimestamp();
|
||||
_perfPendingTerrainMs = (tt1 - tt0) * toMs;
|
||||
_perfPendingArenaMs = (ta1 - tt1) * toMs;
|
||||
|
||||
long tc0 = Stopwatch.GetTimestamp();
|
||||
UpdateCamera((float)delta);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -403,8 +406,8 @@ public partial class Main : Node3D
|
|||
{
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
}
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta);
|
||||
UpdateCamera((float)delta);
|
||||
_arena.Sync(_session, _elapsedSeconds, (float)delta, alpha);
|
||||
UpdateCamera((float)delta, alpha);
|
||||
if (_mapKind == ArenaMapKind.Sion)
|
||||
{
|
||||
_sionMap.UpdateLod(_camera.GlobalPosition);
|
||||
|
|
@ -559,6 +562,7 @@ public partial class Main : Node3D
|
|||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Player;
|
||||
var spec = player.Grid.Spec;
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
{
|
||||
|
|
@ -574,6 +578,13 @@ public partial class Main : Node3D
|
|||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
Vector3 playerCenter = new Vector3(player.X, player.Y, player.Z);
|
||||
float camToCenterProj = (playerCenter - rayOrigin).Dot(rayDir);
|
||||
float minForwardDot = -MathF.Max(spec.HalfWidth, spec.HalfLength) * 0.35f;
|
||||
|
||||
bool IsValidForwardHit(Vector3 pt, float distFromCam) =>
|
||||
(pt - playerCenter).Dot(rayDir) >= minForwardDot &&
|
||||
distFromCam >= camToCenterProj - 0.5f;
|
||||
|
||||
Vector3 castOrigin = rayOrigin;
|
||||
float remainingDist = maxAimDist;
|
||||
|
|
@ -581,8 +592,8 @@ public partial class Main : Node3D
|
|||
Vector3 boxHitPt = Vector3.Zero;
|
||||
bool hasBoxHit = false;
|
||||
|
||||
// Cast against Ymir world, skipping the player's own chassis if hit along the shoulder ray.
|
||||
for (int attempt = 0; attempt < 2; attempt++)
|
||||
// Cast against Ymir world, skipping the player's own chassis and any surface behind the vehicle's forward plane.
|
||||
for (int attempt = 0; attempt < 4 && remainingDist > 1f; attempt++)
|
||||
{
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
|
|
@ -593,25 +604,52 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
if (hit.StableId == playerStableId)
|
||||
float distFromCam = rayOrigin.DistanceTo(pt);
|
||||
if (hit.StableId == playerStableId || !IsValidForwardHit(pt, distFromCam))
|
||||
{
|
||||
float skip = rayOrigin.DistanceTo(pt) + 0.4f;
|
||||
float skip = distFromCam + 0.4f;
|
||||
castOrigin = rayOrigin + rayDir * skip;
|
||||
remainingDist = MathF.Max(1f, maxAimDist - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
boxHitPt = pt;
|
||||
boxDist = rayOrigin.DistanceTo(pt);
|
||||
boxDist = distFromCam;
|
||||
hasBoxHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
bool hasTerrainHit = Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: boxDist,
|
||||
out float tx, out float ty, out float tz, out float terrainDist);
|
||||
float terrainStartDist = 0f;
|
||||
bool hasTerrainHit = false;
|
||||
float tx = 0f, ty = 0f, tz = 0f, terrainDist = maxAimDist;
|
||||
for (int attempt = 0; attempt < 2 && terrainStartDist < boxDist; attempt++)
|
||||
{
|
||||
Vector3 tOrigin = rayOrigin + rayDir * terrainStartDist;
|
||||
float tMaxDist = boxDist - terrainStartDist;
|
||||
if (!Session.State.Terrain.Raycast(
|
||||
tOrigin.X, tOrigin.Y, tOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: tMaxDist,
|
||||
out float hx, out float hy, out float hz, out float localDist))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
float totalDist = terrainStartDist + localDist;
|
||||
var hitPt = new Vector3(hx, hy, hz);
|
||||
if (!IsValidForwardHit(hitPt, totalDist))
|
||||
{
|
||||
terrainStartDist = MathF.Max(totalDist + 0.5f, camToCenterProj - 0.4f);
|
||||
continue;
|
||||
}
|
||||
|
||||
tx = hx;
|
||||
ty = hy;
|
||||
tz = hz;
|
||||
terrainDist = totalDist;
|
||||
hasTerrainHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasTerrainHit && terrainDist <= boxDist)
|
||||
{
|
||||
|
|
@ -627,52 +665,74 @@ public partial class Main : Node3D
|
|||
return (farPt.X, farPt.Y, farPt.Z);
|
||||
}
|
||||
|
||||
private Vector3 ComputeTargetAnchor(ContenderState p)
|
||||
{
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float upOffset = Mathf.Lerp(3.2f, 6.5f, heightT);
|
||||
float rightOffset = Mathf.Lerp(1.6f, 2.8f, heightT);
|
||||
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
return new Vector3(p.X, p.Y + (upOffset - spec.HalfHeight), p.Z) + camRight * rightOffset;
|
||||
}
|
||||
|
||||
private void UpdateCamera(float dt)
|
||||
private void UpdateCamera(float dt, float alpha)
|
||||
{
|
||||
var p = Session.State.Player;
|
||||
var spec = p.Grid.Spec;
|
||||
float heightT = Math.Clamp((spec.HalfHeight - 0.75f) / (2.35f - 0.75f), 0f, 1.2f);
|
||||
float backDist = Mathf.Lerp(7.5f, 12.5f, heightT) * _cameraZoom;
|
||||
var (posInterp, _, _) = Session.GetInterpolatedContenderPose(p.Id, alpha);
|
||||
|
||||
Vector3 targetAnchor = ComputeTargetAnchor(p);
|
||||
float blend = dt >= 1f ? 1f : 1f - MathF.Exp(-dt * 16f);
|
||||
_cameraSmoothedAnchor = _cameraSmoothedAnchor.Lerp(targetAnchor, blend);
|
||||
float rightOffset = MathF.Max(1.6f, spec.HalfWidth * 1.15f + 0.8f);
|
||||
float heightOffset = spec.HalfHeight * 1.45f + 1.4f;
|
||||
float boundingR = MathF.Max(spec.HalfWidth, MathF.Max(spec.HalfHeight * 0.72f, spec.HalfLength * 0.90f));
|
||||
float backDist = Math.Clamp(boundingR * 2.15f + 4.2f, 7.2f, 19.5f) * _cameraZoom;
|
||||
float targetShoulderY = (posInterp.Y - spec.HalfHeight) + heightOffset;
|
||||
|
||||
if (_lastCamChassisId != spec.Id || dt >= 1f)
|
||||
{
|
||||
_smoothedShoulderY = targetShoulderY;
|
||||
_lastCamChassisId = spec.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
float yBlend = 1f - MathF.Exp(-dt * 24f);
|
||||
_smoothedShoulderY = Mathf.Lerp(_smoothedShoulderY, targetShoulderY, yBlend);
|
||||
}
|
||||
|
||||
var pivot = new Vector3(posInterp.X, _smoothedShoulderY, posInterp.Z);
|
||||
var camRight = new Vector3(-MathF.Cos(_cameraYaw), 0f, MathF.Sin(_cameraYaw));
|
||||
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
|
||||
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.Up * MathF.Sin(_cameraPitch)).Normalized();
|
||||
|
||||
// Pull camera forward along arm if terrain or static cover blocks the shoulder-to-camera ray
|
||||
// Segment 1: sweep terrain + static Box3D (StableId < ContenderStableIdBase) from pivot along camRight * rightOffset
|
||||
float effectiveRight = rightOffset;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
pivot.X, pivot.Y, pivot.Z,
|
||||
camRight.X, camRight.Y, camRight.Z,
|
||||
rightOffset,
|
||||
out _, out _, out _, out float rightTerrainDist))
|
||||
{
|
||||
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, rightTerrainDist - 0.45f));
|
||||
}
|
||||
var rightBoxHit = Session.World.CastRayClosest(
|
||||
(pivot.X, pivot.Y, pivot.Z),
|
||||
(camRight.X * effectiveRight, camRight.Y * effectiveRight, camRight.Z * effectiveRight));
|
||||
if (rightBoxHit.Hit && rightBoxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(rightBoxHit.Point.X, rightBoxHit.Point.Y, rightBoxHit.Point.Z);
|
||||
effectiveRight = MathF.Min(effectiveRight, MathF.Max(0f, pivot.DistanceTo(pt) - 0.45f));
|
||||
}
|
||||
Vector3 shoulderPos = pivot + camRight * effectiveRight;
|
||||
|
||||
// Segment 2: sweep terrain + static Box3D from shoulderPos along -lookDir * backDist
|
||||
float effectiveBack = backDist;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z,
|
||||
shoulderPos.X, shoulderPos.Y, shoulderPos.Z,
|
||||
-lookDir.X, -lookDir.Y, -lookDir.Z,
|
||||
backDist,
|
||||
out _, out _, out _, out float terrainDist))
|
||||
out _, out _, out _, out float backTerrainDist))
|
||||
{
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, terrainDist - 0.6f));
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, backTerrainDist - 0.5f));
|
||||
}
|
||||
|
||||
var boxHit = Session.World.CastRayClosest(
|
||||
(_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z),
|
||||
var backBoxHit = Session.World.CastRayClosest(
|
||||
(shoulderPos.X, shoulderPos.Y, shoulderPos.Z),
|
||||
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
|
||||
if (boxHit.Hit && boxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
if (backBoxHit.Hit && backBoxHit.StableId < ArenaSession.ContenderStableIdBase)
|
||||
{
|
||||
var pt = new Vector3(boxHit.Point.X, boxHit.Point.Y, boxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, _cameraSmoothedAnchor.DistanceTo(pt) - 0.5f));
|
||||
var pt = new Vector3(backBoxHit.Point.X, backBoxHit.Point.Y, backBoxHit.Point.Z);
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(0.6f, shoulderPos.DistanceTo(pt) - 0.5f));
|
||||
}
|
||||
|
||||
Vector3 camPos = _cameraSmoothedAnchor - lookDir * effectiveBack;
|
||||
Vector3 camPos = shoulderPos - lookDir * effectiveBack;
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue