From a8cdd143ca944c7a289a2b018d401f9f7616e642 Mon Sep 17 00:00:00 2001 From: Brajanowski Date: Sat, 7 Jun 2025 14:42:50 +0200 Subject: [PATCH] moved spring math to rebootkit --- Assets/RebootKit | 2 +- Assets/jelycho/Code/Player/CameraSpring.cs | 35 +++++-------------- .../jelycho/Code/Player/PlayerController.cs | 16 ++++----- Assets/jelycho/Input.meta | 8 +++++ .../Input/controls_jelycho.inputactions | 5 +++ .../Input/controls_jelycho.inputactions.meta | 14 ++++++++ 6 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 Assets/jelycho/Input.meta create mode 100644 Assets/jelycho/Input/controls_jelycho.inputactions create mode 100644 Assets/jelycho/Input/controls_jelycho.inputactions.meta diff --git a/Assets/RebootKit b/Assets/RebootKit index e534ea7..f8fbe10 160000 --- a/Assets/RebootKit +++ b/Assets/RebootKit @@ -1 +1 @@ -Subproject commit e534ea7596fe90439f256e63fbb1a7701044e0c2 +Subproject commit f8fbe10c562ae69ac91f37b76570cf0bd7a5ebe2 diff --git a/Assets/jelycho/Code/Player/CameraSpring.cs b/Assets/jelycho/Code/Player/CameraSpring.cs index 0625f11..fe4f7c3 100644 --- a/Assets/jelycho/Code/Player/CameraSpring.cs +++ b/Assets/jelycho/Code/Player/CameraSpring.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using RebootKit.Engine.Foundation; +using UnityEngine; namespace RealityReboot.jelycho.Player { public class CameraSpring : MonoBehaviour { @@ -18,12 +19,12 @@ namespace RealityReboot.jelycho.Player { } public void UpdateSpring(float deltaTime, Vector3 up, Vector3 right, Vector3 forward) { - Spring(ref m_SpringPosition, - ref m_SpringVelocity, - transform.position, - m_HalfLife, - m_Frequency, - deltaTime); + MathUtility.Spring(ref m_SpringPosition, + ref m_SpringVelocity, + transform.position, + m_HalfLife, + m_Frequency, + deltaTime); Vector3 localSpringPosition = m_SpringPosition - transform.position; float springHeight = Vector3.Dot(localSpringPosition, up); @@ -35,25 +36,5 @@ namespace RealityReboot.jelycho.Player { 0.0f, springSideways * m_SidewaysAngularDisplacement); } - - // Source: https://allenchou.net/2015/04/game-math-precise-control-over-numeric-springing/ - static void Spring(ref Vector3 current, - ref Vector3 velocity, - Vector3 target, - float halfLife, - float frequency, - float timeStep) { - - float dampingRatio = -Mathf.Log(0.5f) / (frequency * halfLife); - float f = 1.0f + 2.0f * timeStep * dampingRatio * frequency; - float oo = frequency * frequency; - float hoo = timeStep * oo; - float hhoo = timeStep * hoo; - float detInv = 1.0f / (f + hhoo); - Vector3 detX = f * current + timeStep * velocity + hhoo * target; - Vector3 detV = velocity + hoo * (target - current); - current = detX * detInv; - velocity = detV * detInv; - } } } \ No newline at end of file diff --git a/Assets/jelycho/Code/Player/PlayerController.cs b/Assets/jelycho/Code/Player/PlayerController.cs index 8dd3012..e56d06d 100755 --- a/Assets/jelycho/Code/Player/PlayerController.cs +++ b/Assets/jelycho/Code/Player/PlayerController.cs @@ -52,7 +52,7 @@ namespace RealityReboot.jelycho.Player { } Vector2 lookInput = SensitivityReader.Read(m_Config.lookActionReference.action); - m_FPPActor.Look(lookInput * FPPConfig.s_MouseSensitivity.FloatValue); + m_FPPActor.Look(lookInput * FPPConfig.MouseSensitivity.FloatValue); Vector2 moveInput = m_Config.moveActionReference.action.ReadValue(); m_FPPActor.SetMoveInput(moveInput); @@ -74,7 +74,7 @@ namespace RealityReboot.jelycho.Player { [Serializable] public class Config { - [FormerlySerializedAs("fppActorPrefab")] public AssetReferenceT playerActorPrefab; + public AssetReferenceT playerActorPrefab; public InputActionReference moveActionReference; public InputActionReference lookActionReference; @@ -87,9 +87,9 @@ namespace RealityReboot.jelycho.Player { } 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; - [ConfigVar("fpp.gamepad.sens", 4.0f, "Gamepad look sensitivity")] public static ConfigVar s_GamepadSensitivity; + [ConfigVar("fpp.mouse.sens", 0.25f, "Mouse look sensitivity")] public static ConfigVar MouseSensitivity; + [ConfigVar("fpp.mouse.invert.y", 0, "Invert mouse look")] public static ConfigVar MouseInvertY; + [ConfigVar("fpp.gamepad.sens", 4.0f, "Gamepad look sensitivity")] public static ConfigVar GamepadSensitivity; } public static class SensitivityReader { @@ -103,11 +103,11 @@ namespace RealityReboot.jelycho.Player { bool isGamepad = action.activeControl.device is Gamepad; if (isGamepad) { - sensitivity *= FPPConfig.s_GamepadSensitivity.FloatValue; + sensitivity *= FPPConfig.GamepadSensitivity.FloatValue; } else { - sensitivity *= FPPConfig.s_MouseSensitivity.FloatValue; + sensitivity *= FPPConfig.MouseSensitivity.FloatValue; - if (FPPConfig.s_MouseInvertY.IndexValue == 1) { + if (FPPConfig.MouseInvertY.IndexValue == 1) { sensitivity.y *= -1; } } diff --git a/Assets/jelycho/Input.meta b/Assets/jelycho/Input.meta new file mode 100644 index 0000000..2398f34 --- /dev/null +++ b/Assets/jelycho/Input.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c47ef0a0dcfbe6d4aa3b23261a96f53f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/jelycho/Input/controls_jelycho.inputactions b/Assets/jelycho/Input/controls_jelycho.inputactions new file mode 100644 index 0000000..1f3aaee --- /dev/null +++ b/Assets/jelycho/Input/controls_jelycho.inputactions @@ -0,0 +1,5 @@ +{ + "name": "controls_jelycho", + "maps": [], + "controlSchemes": [] +} \ No newline at end of file diff --git a/Assets/jelycho/Input/controls_jelycho.inputactions.meta b/Assets/jelycho/Input/controls_jelycho.inputactions.meta new file mode 100644 index 0000000..563e8e5 --- /dev/null +++ b/Assets/jelycho/Input/controls_jelycho.inputactions.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: bf6c2a363dbaef244afe38b9ff9fecc5 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} + generateWrapperCode: 0 + wrapperCodePath: + wrapperClassName: + wrapperCodeNamespace: