Fix : Slope bug for player & add case for inifinite stairs
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 134e0811334c5814e96a4823d9665656
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 445844e5540fe42449d9a96cd68cbcea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-3947132882786938876
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
|
||||
version: 10
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: StairsMaterial
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses:
|
||||
- MOTIONVECTORS
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AddPrecomputedVelocity: 0
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _XRMotionVectorsPass: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 0.3773585, g: 0.3773585, b: 0.3773585, a: 1}
|
||||
- _Color: {r: 0.37735847, g: 0.37735847, b: 0.37735847, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bb237e5d23b5264b8fcb45d620a4108
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baf901c128ce7a644b7b1737ba04de04
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+1845
File diff suppressed because it is too large
Load Diff
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b278a20a2783def489d009364c988771
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+3233
File diff suppressed because it is too large
Load Diff
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3159084da89126c4f8f26519f0c6f75e
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+5887
File diff suppressed because it is too large
Load Diff
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b096230e5db7f84fbdc9ec1f398c205
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 629e2f358900b4e46b9b43539224cba1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+218
-83
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -8,6 +8,9 @@ namespace Unheimlich.Features.Player
|
||||
/// Simulates camera head bobbing motion during player movement and idle states.
|
||||
/// Smoothly transitions between idle, walk and run bob parameters.
|
||||
/// Adds a subtle Z-axis roll to the bob and a strafe tilt applied in LateUpdate.
|
||||
///
|
||||
/// Sprint bob is automatically disabled when OctoPlayer.CanRun is false,
|
||||
/// since IsRunning already returns false in that case.
|
||||
/// </summary>
|
||||
public class CameraHeadBob : MonoBehaviour
|
||||
{
|
||||
@@ -15,15 +18,15 @@ namespace Unheimlich.Features.Player
|
||||
private Vector3 _startLocalPos;
|
||||
|
||||
// Smoothly interpolated bob parameters to avoid brutal state switches.
|
||||
private float _currentBobSpeed = 0f;
|
||||
private float _currentBobSpeed = 0f;
|
||||
private float _currentBobAmplitude = 0f;
|
||||
|
||||
// Strafe tilt (Z roll applied in LateUpdate, after OctoPlayer sets camera pitch).
|
||||
private float _currentTilt = 0f;
|
||||
|
||||
private HeadBobMode _overrideMode = HeadBobMode.Normal;
|
||||
private bool _hasOverride = false;
|
||||
private Coroutine _resetCoroutine;
|
||||
private HeadBobMode _overrideMode = HeadBobMode.Normal;
|
||||
private bool _hasOverride = false;
|
||||
private Coroutine _resetCoroutine;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -32,7 +35,7 @@ namespace Unheimlich.Features.Player
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (PlayerController.Instance == null || PlayerController.Instance.CharController == null)
|
||||
if (OctoCore.Components.OctoPlayer.Instance == null || PlayerController.Instance == null || PlayerController.Instance.CharController == null)
|
||||
return;
|
||||
|
||||
var settings = PlayerController.Instance.CameraEffects?.Settings;
|
||||
@@ -66,20 +69,21 @@ namespace Unheimlich.Features.Player
|
||||
}
|
||||
|
||||
// Drive bob parameters directly from the actual physics velocity.
|
||||
// This is naturally in sync with OctoPlayer's inertia — no extra lerp needed.
|
||||
float horizontalSpeed = new Vector3(
|
||||
PlayerController.Instance.CharController.velocity.x,
|
||||
0f,
|
||||
PlayerController.Instance.CharController.velocity.z).magnitude;
|
||||
PlayerController.Instance.CharController.velocity.z
|
||||
).magnitude;
|
||||
|
||||
bool isRunning = PlayerController.Instance.IsRunning;
|
||||
// IsRunning already returns false when OctoPlayer.CanRun is off —
|
||||
// so the bob falls back to walk params automatically.
|
||||
bool isRunning = OctoCore.Components.OctoPlayer.Instance.IsRunning;
|
||||
|
||||
// Normalise: 0 = stopped, 1 = full walk/run speed (m/s converted from km/h ÷ 3.6).
|
||||
const float WalkSpeedMs = 10f / 3.6f;
|
||||
const float RunSpeedMs = 20f / 3.6f;
|
||||
|
||||
float maxSpeed = isRunning ? RunSpeedMs : WalkSpeedMs;
|
||||
float t = Mathf.Clamp01(horizontalSpeed / maxSpeed);
|
||||
float maxSpeed = isRunning ? RunSpeedMs : WalkSpeedMs;
|
||||
float t = Mathf.Clamp01(horizontalSpeed / maxSpeed);
|
||||
|
||||
float targetSpeed = Mathf.Lerp(settings.idleBobSpeed, isRunning ? settings.runBobSpeed : settings.walkBobSpeed, t);
|
||||
float targetAmplitude = Mathf.Lerp(settings.idleBobAmplitude, isRunning ? settings.runBobAmplitude : settings.walkBobAmplitude, t);
|
||||
@@ -99,19 +103,16 @@ namespace Unheimlich.Features.Player
|
||||
var settings = PlayerController.Instance.CameraEffects?.Settings;
|
||||
if (settings == null) return;
|
||||
|
||||
// Strafe direction in local space using actual character velocity.
|
||||
Vector3 velocity = PlayerController.Instance.CharController.velocity;
|
||||
float strafeAmount = Vector3.Dot(velocity, PlayerController.Instance.transform.right);
|
||||
Vector3 velocity = PlayerController.Instance.CharController.velocity;
|
||||
float strafeAmount = Vector3.Dot(velocity, PlayerController.Instance.transform.right);
|
||||
|
||||
// Normalise by run speed (km/h → m/s: / 3.6) to get a -1..1 factor.
|
||||
float runSpeedMs = PlayerController.Instance.Movement != null ? 20f / 3.6f : 5.5f;
|
||||
float strafeFactor = Mathf.Clamp(strafeAmount / runSpeedMs, -1f, 1f);
|
||||
float runSpeedMs = PlayerController.Instance.Movement != null ? 20f / 3.6f : 5.5f;
|
||||
float strafeFactor = Mathf.Clamp(strafeAmount / runSpeedMs, -1f, 1f);
|
||||
|
||||
float targetTilt = -strafeFactor * settings.strafeTiltAngle;
|
||||
_currentTilt = Mathf.Lerp(_currentTilt, targetTilt, Time.deltaTime * settings.strafeTiltSpeed);
|
||||
float targetTilt = -strafeFactor * settings.strafeTiltAngle;
|
||||
_currentTilt = Mathf.Lerp(_currentTilt, targetTilt, Time.deltaTime * settings.strafeTiltSpeed);
|
||||
|
||||
// Compose with the existing local rotation (OctoPlayer already wrote pitch into it).
|
||||
Quaternion baseRot = transform.localRotation;
|
||||
Quaternion baseRot = transform.localRotation;
|
||||
transform.localRotation = baseRot * Quaternion.Euler(0f, 0f, _currentTilt);
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ namespace Unheimlich.Features.Player
|
||||
public void SetMode(HeadBobMode mode)
|
||||
{
|
||||
_overrideMode = mode;
|
||||
_hasOverride = true;
|
||||
_hasOverride = true;
|
||||
}
|
||||
|
||||
/// <summary>Clears any active mode override and returns to Normal.</summary>
|
||||
@@ -147,25 +148,18 @@ namespace Unheimlich.Features.Player
|
||||
|
||||
// ── Private helpers ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Sets bob speed and amplitude directly without lerp — velocity already carries the inertia.</summary>
|
||||
private void SetBobDirect(float speed, float amplitude)
|
||||
{
|
||||
_currentBobSpeed = speed;
|
||||
_currentBobAmplitude = amplitude;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Advances the bob timer and writes the resulting local position offset.
|
||||
/// Includes a subtle Z roll (Lissajous third axis) for organic feel.
|
||||
/// </summary>
|
||||
private void ApplySmoothedBob(float rollAmplitude)
|
||||
{
|
||||
_timer += Time.deltaTime * _currentBobSpeed;
|
||||
|
||||
float x = Mathf.Sin(_timer * 0.5f) * _currentBobAmplitude * 0.6f;
|
||||
float y = Mathf.Cos(_timer) * _currentBobAmplitude;
|
||||
|
||||
// Micro Z roll: half frequency of Y so it drifts independently.
|
||||
float x = Mathf.Sin(_timer * 0.5f) * _currentBobAmplitude * 0.6f;
|
||||
float y = Mathf.Cos(_timer) * _currentBobAmplitude;
|
||||
float roll = Mathf.Sin(_timer * 0.5f + Mathf.PI * 0.25f) * rollAmplitude * (_currentBobAmplitude / Mathf.Max(0.001f, 0.03f));
|
||||
|
||||
Vector3 newPos = _startLocalPos;
|
||||
@@ -173,21 +167,18 @@ namespace Unheimlich.Features.Player
|
||||
newPos.y += y;
|
||||
transform.localPosition = newPos;
|
||||
|
||||
// Store roll so LateUpdate can composite it with the strafe tilt.
|
||||
// We write only the bob-driven roll here; LateUpdate adds strafe tilt on top.
|
||||
Quaternion bobRot = Quaternion.Euler(0f, 0f, roll);
|
||||
transform.localRotation = bobRot;
|
||||
transform.localRotation = Quaternion.Euler(0f, 0f, roll);
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator LerpToZeroCoroutine(float duration)
|
||||
{
|
||||
Vector3 startPos = transform.localPosition;
|
||||
float elapsed = 0f;
|
||||
float elapsed = 0f;
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / duration);
|
||||
float t = Mathf.Clamp01(elapsed / duration);
|
||||
transform.localPosition = Vector3.Lerp(startPos, _startLocalPos, t);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user