moved spring math to rebootkit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Vector2>();
|
||||
m_FPPActor.SetMoveInput(moveInput);
|
||||
@@ -74,7 +74,7 @@ namespace RealityReboot.jelycho.Player {
|
||||
|
||||
[Serializable]
|
||||
public class Config {
|
||||
[FormerlySerializedAs("fppActorPrefab")] public AssetReferenceT<GameObject> playerActorPrefab;
|
||||
public AssetReferenceT<GameObject> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user