moved spring math to rebootkit
This commit is contained in:
Submodule Assets/RebootKit updated: e534ea7596...f8fbe10c56
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
8
Assets/jelycho/Input.meta
Normal file
8
Assets/jelycho/Input.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c47ef0a0dcfbe6d4aa3b23261a96f53f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
5
Assets/jelycho/Input/controls_jelycho.inputactions
Normal file
5
Assets/jelycho/Input/controls_jelycho.inputactions
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "controls_jelycho",
|
||||
"maps": [],
|
||||
"controlSchemes": []
|
||||
}
|
||||
14
Assets/jelycho/Input/controls_jelycho.inputactions.meta
Normal file
14
Assets/jelycho/Input/controls_jelycho.inputactions.meta
Normal file
@@ -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:
|
||||
Reference in New Issue
Block a user