Cut 1: 1536m desert relief, terrain/cover LOS detection, tier positioning, 3P shoulder cam
This commit is contained in:
parent
3bd66c3b64
commit
3221ca1d0c
19 changed files with 1558 additions and 316 deletions
212
client/Main.cs
212
client/Main.cs
|
|
@ -18,8 +18,10 @@ public partial class Main : Node3D
|
|||
private ArenaSession? _session;
|
||||
|
||||
private PlayerInput? _scriptedInput;
|
||||
private float _cameraDistance = 30f;
|
||||
private Vector3 _cameraSmoothedTarget = Vector3.Zero;
|
||||
private float _cameraYaw;
|
||||
private float _cameraPitch = Mathf.DegToRad(12f);
|
||||
private float _cameraZoom = 1.0f;
|
||||
private Vector3 _cameraSmoothedAnchor = Vector3.Zero;
|
||||
private float _elapsedSeconds;
|
||||
private bool _interactQueued;
|
||||
private int _seed = 42;
|
||||
|
|
@ -30,6 +32,7 @@ public partial class Main : Node3D
|
|||
public Hud Hud => _hud;
|
||||
public string? Failure { get; private set; }
|
||||
public int Seed => _seed;
|
||||
public float CameraYaw => _cameraYaw;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -43,14 +46,14 @@ public partial class Main : Node3D
|
|||
|
||||
_camera = new Camera3D
|
||||
{
|
||||
Name = "TacticalCamera",
|
||||
Name = "ShoulderCamera",
|
||||
Current = true,
|
||||
Fov = 48f,
|
||||
Far = 520f
|
||||
Fov = 58f,
|
||||
Far = 1800f
|
||||
};
|
||||
AddChild(_camera);
|
||||
|
||||
_hud = new Hud(() => _session, OnEquipCargo) { Name = "Hud" };
|
||||
_hud = new Hud(() => _session, OnEquipCargo, () => _cameraYaw) { Name = "Hud" };
|
||||
AddChild(_hud);
|
||||
|
||||
Reset(_seed);
|
||||
|
|
@ -73,11 +76,21 @@ public partial class Main : Node3D
|
|||
{
|
||||
_session = new ArenaSession(seed);
|
||||
var p = _session.State.Player;
|
||||
_cameraSmoothedTarget = new Vector3(p.X, p.Y, p.Z);
|
||||
_cameraYaw = p.Yaw;
|
||||
_cameraPitch = Mathf.DegToRad(12f);
|
||||
_cameraZoom = 1.0f;
|
||||
_cameraSmoothedAnchor = ComputeTargetAnchor(p);
|
||||
|
||||
_terrain.InvalidateAll();
|
||||
_terrain.Sync(_session.State.Terrain);
|
||||
_arena.Sync(_session, _elapsedSeconds);
|
||||
UpdateCamera(1f);
|
||||
_hud.Sync(_session);
|
||||
|
||||
if (DisplayServer.GetName() != "headless" && !_hud.GarageExpanded)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -90,6 +103,16 @@ public partial class Main : Node3D
|
|||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseMotion mm && Input.MouseMode == Input.MouseModeEnum.Captured)
|
||||
{
|
||||
_cameraYaw -= mm.Relative.X * 0.0028f;
|
||||
_cameraPitch = Math.Clamp(
|
||||
_cameraPitch + mm.Relative.Y * 0.0024f,
|
||||
Mathf.DegToRad(-18f),
|
||||
Mathf.DegToRad(38f));
|
||||
return;
|
||||
}
|
||||
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
switch (key.Keycode)
|
||||
|
|
@ -99,14 +122,23 @@ public partial class Main : Node3D
|
|||
break;
|
||||
case Key.Tab:
|
||||
_hud.ToggleGarage();
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = _hud.GarageExpanded
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
break;
|
||||
case Key.R:
|
||||
Reset(_seed + 1);
|
||||
break;
|
||||
case Key.Escape:
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Confined
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Confined;
|
||||
if (DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseMode == Input.MouseModeEnum.Captured
|
||||
? Input.MouseModeEnum.Visible
|
||||
: Input.MouseModeEnum.Captured;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,11 +146,19 @@ public partial class Main : Node3D
|
|||
{
|
||||
if (mb.ButtonIndex == MouseButton.WheelUp)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance - 2.5f, 16f, 58f);
|
||||
_cameraZoom = Math.Clamp(_cameraZoom - 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.WheelDown)
|
||||
{
|
||||
_cameraDistance = Math.Clamp(_cameraDistance + 2.5f, 16f, 58f);
|
||||
_cameraZoom = Math.Clamp(_cameraZoom + 0.08f, 0.75f, 1.6f);
|
||||
}
|
||||
else if (mb.ButtonIndex == MouseButton.Left &&
|
||||
Input.MouseMode == Input.MouseModeEnum.Visible &&
|
||||
!_hud.GarageExpanded &&
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position) &&
|
||||
DisplayServer.GetName() != "headless")
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,11 +201,11 @@ public partial class Main : Node3D
|
|||
if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left)) steer -= 1f;
|
||||
|
||||
bool brake = Input.IsKeyPressed(Key.Space);
|
||||
Vector2 mousePos = GetViewport().GetMousePosition();
|
||||
bool pointerOnHud = _hud.IsPointerOverInteractiveHud(mousePos);
|
||||
bool pointerOnHud = Input.MouseMode != Input.MouseModeEnum.Captured &&
|
||||
_hud.IsPointerOverInteractiveHud(GetViewport().GetMousePosition());
|
||||
bool fire = !pointerOnHud && Input.IsMouseButtonPressed(MouseButton.Left);
|
||||
|
||||
var (aimX, aimZ) = ComputeMouseTerrainAim(mousePos);
|
||||
var (aimX, aimY, aimZ) = ComputeCenterScreenAim();
|
||||
return new PlayerInput(
|
||||
Throttle: throttle,
|
||||
Steer: steer,
|
||||
|
|
@ -173,48 +213,135 @@ public partial class Main : Node3D
|
|||
AimWorldZ: aimZ,
|
||||
Fire: fire,
|
||||
InteractPickup: _interactQueued,
|
||||
Brake: brake);
|
||||
Brake: brake,
|
||||
AimWorldY: aimY);
|
||||
}
|
||||
|
||||
private (float AimX, float AimZ) ComputeMouseTerrainAim(Vector2 mousePos)
|
||||
private (float AimX, float AimY, float AimZ) ComputeCenterScreenAim()
|
||||
{
|
||||
var player = Session.State.Player;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(mousePos);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(mousePos);
|
||||
|
||||
if (Session.State.Terrain.Raycast(
|
||||
rayOrigin.X, rayOrigin.Y, rayOrigin.Z,
|
||||
rayDir.X, rayDir.Y, rayDir.Z,
|
||||
maxDistance: 320f,
|
||||
out float hx, out _, out float hz, out _))
|
||||
Vector2 screenSize = GetViewport().GetVisibleRect().Size;
|
||||
if (screenSize.X < 2f || screenSize.Y < 2f)
|
||||
{
|
||||
return (hx, hz);
|
||||
return (
|
||||
player.X + MathF.Sin(_cameraYaw) * 40f,
|
||||
player.Y,
|
||||
player.Z + MathF.Cos(_cameraYaw) * 40f);
|
||||
}
|
||||
|
||||
if (MathF.Abs(rayDir.Y) > 1e-4f)
|
||||
Vector2 center = screenSize * 0.5f;
|
||||
Vector3 rayOrigin = _camera.ProjectRayOrigin(center);
|
||||
Vector3 rayDir = _camera.ProjectRayNormal(center);
|
||||
|
||||
const float maxAimDist = 450f;
|
||||
ulong playerStableId = ArenaSession.ContenderStableIdBase + (ulong)player.Id;
|
||||
|
||||
Vector3 castOrigin = rayOrigin;
|
||||
float remainingDist = maxAimDist;
|
||||
float boxDist = maxAimDist;
|
||||
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++)
|
||||
{
|
||||
float t = (player.Y - rayOrigin.Y) / rayDir.Y;
|
||||
if (t > 0f)
|
||||
var hit = Session.World.CastRayClosest(
|
||||
(castOrigin.X, castOrigin.Y, castOrigin.Z),
|
||||
(rayDir.X * remainingDist, rayDir.Y * remainingDist, rayDir.Z * remainingDist));
|
||||
if (!hit.Hit)
|
||||
{
|
||||
Vector3 p = rayOrigin + rayDir * t;
|
||||
return (p.X, p.Z);
|
||||
break;
|
||||
}
|
||||
|
||||
var pt = new Vector3(hit.Point.X, hit.Point.Y, hit.Point.Z);
|
||||
if (hit.StableId == playerStableId)
|
||||
{
|
||||
float skip = rayOrigin.DistanceTo(pt) + 0.4f;
|
||||
castOrigin = rayOrigin + rayDir * skip;
|
||||
remainingDist = MathF.Max(1f, maxAimDist - skip);
|
||||
continue;
|
||||
}
|
||||
|
||||
boxHitPt = pt;
|
||||
boxDist = rayOrigin.DistanceTo(pt);
|
||||
hasBoxHit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return (player.X + MathF.Sin(player.Yaw) * 25f, player.Z + MathF.Cos(player.Yaw) * 25f);
|
||||
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);
|
||||
|
||||
if (hasTerrainHit && terrainDist <= boxDist)
|
||||
{
|
||||
return (tx, ty, tz);
|
||||
}
|
||||
|
||||
if (hasBoxHit)
|
||||
{
|
||||
return (boxHitPt.X, boxHitPt.Y, boxHitPt.Z);
|
||||
}
|
||||
|
||||
Vector3 farPt = rayOrigin + rayDir * 320f;
|
||||
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)
|
||||
{
|
||||
var p = Session.State.Player;
|
||||
var target = new Vector3(p.X, p.Y + 1.0f, p.Z);
|
||||
float blend = 1f - MathF.Exp(-dt * 9f);
|
||||
_cameraSmoothedTarget = _cameraSmoothedTarget.Lerp(target, blend);
|
||||
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;
|
||||
|
||||
// Angled tactical 3rd-person desert chase view
|
||||
Vector3 offset = new Vector3(0f, _cameraDistance * 0.78f, -_cameraDistance * 0.72f);
|
||||
_camera.GlobalPosition = _cameraSmoothedTarget + offset;
|
||||
_camera.LookAt(_cameraSmoothedTarget, Vector3.Up);
|
||||
Vector3 targetAnchor = ComputeTargetAnchor(p);
|
||||
float blend = dt >= 1f ? 1f : 1f - MathF.Exp(-dt * 16f);
|
||||
_cameraSmoothedAnchor = _cameraSmoothedAnchor.Lerp(targetAnchor, blend);
|
||||
|
||||
var camFwdHoriz = new Vector3(MathF.Sin(_cameraYaw), 0f, MathF.Cos(_cameraYaw));
|
||||
var lookDir = (camFwdHoriz * MathF.Cos(_cameraPitch) - Vector3.UnitY * MathF.Sin(_cameraPitch)).Normalized();
|
||||
|
||||
// Pull camera forward along arm if terrain or static cover blocks the shoulder-to-camera ray
|
||||
float effectiveBack = backDist;
|
||||
if (Session.State.Terrain.Raycast(
|
||||
_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z,
|
||||
-lookDir.X, -lookDir.Y, -lookDir.Z,
|
||||
backDist,
|
||||
out _, out _, out _, out float terrainDist))
|
||||
{
|
||||
effectiveBack = MathF.Min(effectiveBack, MathF.Max(1.6f, terrainDist - 0.6f));
|
||||
}
|
||||
|
||||
var boxHit = Session.World.CastRayClosest(
|
||||
(_cameraSmoothedAnchor.X, _cameraSmoothedAnchor.Y, _cameraSmoothedAnchor.Z),
|
||||
(-lookDir.X * effectiveBack, -lookDir.Y * effectiveBack, -lookDir.Z * effectiveBack));
|
||||
if (boxHit.Hit && boxHit.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));
|
||||
}
|
||||
|
||||
Vector3 camPos = _cameraSmoothedAnchor - lookDir * effectiveBack;
|
||||
float minTerrainY = Session.State.Terrain.SampleHeight(camPos.X, camPos.Z) + 1.2f;
|
||||
if (camPos.Y < minTerrainY)
|
||||
{
|
||||
camPos.Y = minTerrainY;
|
||||
}
|
||||
|
||||
_camera.GlobalPosition = camPos;
|
||||
_camera.LookAt(camPos + lookDir * 60f, Vector3.Up);
|
||||
}
|
||||
|
||||
private void OnEquipCargo(int cargoIndex, string hardpointId)
|
||||
|
|
@ -248,8 +375,11 @@ public partial class Main : Node3D
|
|||
AmbientLightSource = Godot.Environment.AmbientSource.Sky,
|
||||
AmbientLightEnergy = 0.55f,
|
||||
FogEnabled = true,
|
||||
FogLightColor = new Color(0.74f, 0.55f, 0.38f),
|
||||
FogDensity = 0.0022f
|
||||
FogMode = Godot.Environment.FogModeEnum.Depth,
|
||||
FogLightColor = new Color(0.76f, 0.57f, 0.39f),
|
||||
FogDensity = 0.72f,
|
||||
FogDepthBegin = 380f,
|
||||
FogDepthEnd = 1100f
|
||||
};
|
||||
AddChild(new WorldEnvironment { Name = "WorldEnv", Environment = env });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue