Initial commit

This commit is contained in:
2025-05-20 17:31:26 +02:00
commit fb56f2e936
215 changed files with 5119 additions and 0 deletions

View File

@ -0,0 +1,42 @@
using Godot;
namespace PolarBears.PlayerControllerAddon;
public partial class FieldOfView: Node3D
{
[Export(PropertyHint.Range, "0,180,0.1,degrees")]
public float BaseFov { get; set; } = 75.0f;
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
public float FovChangeFactor { get; set; } = 1.2f;
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
public float FovChangeSpeed { get; set; } = 6.25f;
private Camera3D _camera;
public void Init(Camera3D cam)
{
_camera = cam;
}
public struct FovParameters
{
public bool IsCrouchingHeight;
public float Delta;
public float SprintSpeed;
public Vector3 Velocity;
}
public void PerformFovAdjustment(FovParameters parameters)
{
float velocityClamped = Mathf.Clamp(
parameters.Velocity.Length(), 0.5f, parameters.SprintSpeed * 2.0f);
float targetFov = BaseFov + FovChangeFactor * velocityClamped;
if (parameters.IsCrouchingHeight){
targetFov = BaseFov - FovChangeFactor * velocityClamped;
}
_camera.Fov = Mathf.Lerp(_camera.Fov, targetFov, parameters.Delta * FovChangeSpeed);
}
}