This commit is contained in:
2025-05-14 10:52:53 +02:00
parent 1e190fe94b
commit f0536f4129
51 changed files with 934 additions and 381 deletions

View File

@@ -5,12 +5,18 @@ namespace RebootKit.FPPKit {
public class FPPLocomotion : MonoBehaviour {
[SerializeField] CharacterController m_CharacterController;
public float maxStrafeSpeed = 2.0f;
public float maxMovementSpeedBackward = 2.0f;
public float maxMovementSpeed = 4.0f;
public float maxSprintSpeed = 15.0f;
public float jumpHeight = 1.0f;
public float gravity = 10f;
public float maxFallSpeed = 20f;
public float damping = 20.0f;
[Range(0.0f, 1.0f)]
public float airControlRatio = 0.5f;
float3 m_CurrentVelocity;
bool m_IsFalling;
@@ -20,8 +26,12 @@ namespace RebootKit.FPPKit {
float3 m_PendingInputValue;
public bool IsGrounded => m_CharacterController.isGrounded;
public bool IsMovingBackwards { get; private set; }
public bool IsSprinting => m_IsSprinting;
public bool IsStrafing { get; private set; }
public float3 Velocity => m_CurrentVelocity;
public float3 Velocity => m_CurrentVelocity;
public float3 LocalVelocity => m_CharacterController.transform.InverseTransformDirection(m_CurrentVelocity);
void Update() {
ConsumePendingInput();
@@ -42,12 +52,13 @@ namespace RebootKit.FPPKit {
}
void ConsumePendingInput() {
// if (!IsGrounded) {
// m_PendingInputValue = float3.zero;
// return;
// }
if (!IsGrounded) {
m_PendingInputValue *= airControlRatio;
}
m_PendingInputValue.y = 0.0f;
float3 localInputValue = m_CharacterController.transform.InverseTransformDirection(m_PendingInputValue);
float pendingInputMagnitude = math.length(m_PendingInputValue);
float3 direction = float3.zero;
@@ -56,7 +67,21 @@ namespace RebootKit.FPPKit {
direction = math.normalize(m_PendingInputValue);
}
float movementSpeed = m_IsSprinting ? maxSprintSpeed : maxMovementSpeed;
IsStrafing = false;
IsMovingBackwards = false;
float movementSpeed;
if (math.dot(localInputValue, Vector3.forward) <= 0.0f) {
movementSpeed = maxMovementSpeedBackward;
IsMovingBackwards = true;
} else if (m_IsSprinting) {
movementSpeed = maxSprintSpeed;
} else if (math.abs(localInputValue.x) > 0.0f && math.abs(localInputValue.z) < 0.1f) {
movementSpeed = maxStrafeSpeed;
} else {
movementSpeed = maxMovementSpeed;
}
float3 movementVelocity = m_CurrentVelocity;
movementVelocity.y = 0.0f;
movementVelocity += direction * (movementSpeed * pendingInputMagnitude);

View File

@@ -3,6 +3,7 @@ using System.Threading;
using Cysharp.Threading.Tasks;
using RebootKit.Engine;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Main;
using RebootKit.Engine.Services.Console;
using RebootKit.Engine.Services.Input;
using Unity.Mathematics;
@@ -12,7 +13,6 @@ using UnityEngine.InputSystem;
using Object = UnityEngine.Object;
namespace RebootKit.FPPKit {
public static class FPPConfig {
[ConfigVar("fpp.mouse.sens", 0.25f, "Mouse look sensitivity")] public static ConfigVar s_MouseSensitivity;
[ConfigVar("fpp.mouse.invert.y", 0, "Invert mouse look")] public static ConfigVar s_MouseInvertY;
@@ -21,20 +21,28 @@ namespace RebootKit.FPPKit {
public static class SensitivityReader {
public static float2 Read(InputAction action) {
if (action == null || action.activeControl == null) {
return float2.zero;
}
float2 sensitivity = action.ReadValue<Vector2>();
// @TODO: differentiate between gamepad and mouse
sensitivity *= FPPConfig.s_MouseSensitivity.FloatValue;
bool isGamepad = action.activeControl.device is Gamepad;
if (FPPConfig.s_MouseInvertY.IndexValue == 1) {
sensitivity.y *= -1;
if (isGamepad) {
sensitivity *= FPPConfig.s_GamepadSensitivity.FloatValue;
} else {
sensitivity *= FPPConfig.s_MouseSensitivity.FloatValue;
if (FPPConfig.s_MouseInvertY.IndexValue == 1) {
sensitivity.y *= -1;
}
}
return sensitivity;
}
}
public class FPPPlayerController : IController {
readonly Config m_Config;
FPPActor m_FPPActor;