From e7772ebeb5f074d6110c5ac8e68a87df3a0376c1 Mon Sep 17 00:00:00 2001 From: Fredrik Lillemoen Eiding Date: Thu, 30 Nov 2023 03:03:22 +0100 Subject: [PATCH 1/6] Fix terminal velocity for falling, fix jumping direction - There is now 0 drag on Y for players falling, giving no terminal velocity - Remove quirk with floating point rounding by applying fixedUpdate too early --- Assets/Prefabs/Input/Player.prefab | 14 ++++++------- .../Scripts/Control&Input/PlayerMovement.cs | 21 +++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Assets/Prefabs/Input/Player.prefab b/Assets/Prefabs/Input/Player.prefab index 847c67925..5926f701c 100644 --- a/Assets/Prefabs/Input/Player.prefab +++ b/Assets/Prefabs/Input/Player.prefab @@ -59,16 +59,16 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 65335 lookSpeed: 3 - maxVelocity: 10 + maxVelocity: 20 strafeForceGrounded: 60 strafeForceCrouched: 30 - strafeForceInAir: 16 + strafeForceInAir: 10 drag: 6 - airDrag: 2 + airDrag: 1 jumpForce: 10 leapForce: 12.5 - jumpTimeout: 0.5 - leapTimeout: 0.875 + jumpTimeout: 0 + leapTimeout: 0 crouchedHeightOffset: 0.8 airThreshold: 0.4 slopeAngleThreshold: 50 @@ -145,8 +145,8 @@ Rigidbody: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 71015680234268067} serializedVersion: 4 - m_Mass: 10 - m_Drag: 4 + m_Mass: 5 + m_Drag: 0 m_AngularDrag: 0.05 m_CenterOfMass: {x: 0, y: 0, z: 0} m_InertiaTensor: {x: 1, y: 1, z: 1} diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index 47ccf2214..b23c4a6ec 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -43,6 +43,8 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private float airDrag = 2f; + private float chosenDrag = 0; + [SerializeField] private float jumpForce = 10; @@ -185,22 +187,20 @@ private void UpdatePosition(Vector3 input) { case PlayerState.IN_AIR: { - // Strafe slightly with less drag. - body.drag = airDrag; - body.AddForce(input * strafeForceInAir, ForceMode.VelocityChange); - body.AddForce(Vector3.down * MarsGravity, ForceMode.Acceleration); + chosenDrag = airDrag; + body.AddForce(input * strafeForceInAir * Time.deltaTime, ForceMode.VelocityChange); + body.AddForce(Vector3.down * MarsGravity * Time.deltaTime, ForceMode.Acceleration); if (!IsInAir()) state = PlayerState.GROUNDED; break; } case PlayerState.GROUNDED: { - // Strafe normally with heavy drag. - body.drag = drag; + chosenDrag = drag; // Walk along ground normal (adjusted if on heavy slope). var groundNormal = GroundNormal(); var direction = Vector3.ProjectOnPlane(input, groundNormal); - body.AddForce(direction * strafeForce, ForceMode.VelocityChange); - body.AddForce(direction * strafeForce, ForceMode.Impulse); + body.AddForce(direction * strafeForce * Time.deltaTime, ForceMode.VelocityChange); + body.AddForce(direction * strafeForce * Time.deltaTime, ForceMode.Impulse); if (IsInAir()) state = PlayerState.IN_AIR; break; } @@ -210,6 +210,8 @@ private void UpdatePosition(Vector3 input) break; } } + var yDrag = body.velocity.y < 0 ? 0f : body.velocity.y; + body.AddForce(-chosenDrag * body.mass * new Vector3(body.velocity.x, yDrag, body.velocity.z), ForceMode.Force); } private void UpdateRotation() @@ -241,10 +243,11 @@ void OnDrawGizmos() void FixedUpdate() { var positionInput = new Vector3(inputManager.moveInput.x, 0, inputManager.moveInput.y); - UpdatePosition(positionInput * Time.deltaTime); + UpdatePosition(positionInput); // Limit velocity when not grounded if (state == PlayerState.GROUNDED) return; + // TODO: clamp the magnitude instead of individual components body.velocity = new Vector3(Mathf.Clamp(body.velocity.x, -maxVelocity, maxVelocity), body.velocity.y, Mathf.Clamp(body.velocity.z, -maxVelocity, maxVelocity)); } From ad79d6d3157b1b0959044c1b49192dfba46cba37 Mon Sep 17 00:00:00 2001 From: Fredrik Date: Thu, 30 Nov 2023 18:25:00 +0100 Subject: [PATCH 2/6] Add no drag on falling, fix maxVelocity, add consec. leap --- Assets/Prefabs/Input/Player.prefab | 14 ++-- .../Scripts/Control&Input/PlayerMovement.cs | 78 +++++++++++-------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/Assets/Prefabs/Input/Player.prefab b/Assets/Prefabs/Input/Player.prefab index 5926f701c..3dbd2fe5d 100644 --- a/Assets/Prefabs/Input/Player.prefab +++ b/Assets/Prefabs/Input/Player.prefab @@ -59,16 +59,18 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 65335 lookSpeed: 3 - maxVelocity: 20 + groundDrag: 6 + airDrag: 1 + maxVelocityBeforeExtraDamping: 10 + extraDamping: 25 strafeForceGrounded: 60 strafeForceCrouched: 30 - strafeForceInAir: 10 - drag: 6 - airDrag: 1 + strafeForceInAir: 30 jumpForce: 10 leapForce: 12.5 - jumpTimeout: 0 - leapTimeout: 0 + leapTimeout: 0.25 + consecutiveLeapHeightMultiplier: 0.5 + consecutiveLeapForwardMultiplier: 1.5 crouchedHeightOffset: 0.8 airThreshold: 0.4 slopeAngleThreshold: 50 diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index b23c4a6ec..975026bf3 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -23,28 +23,34 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private float lookSpeed = 3; + [Header("Drag")] [SerializeField] - private float maxVelocity = 10; + private float groundDrag = 6f; - private float strafeForce; + [SerializeField] + private float airDrag = 2f; [SerializeField] - private float strafeForceGrounded = 60; + private float maxVelocityBeforeExtraDamping = 20f; [SerializeField] - private float strafeForceCrouched = 30; + private float extraDamping = 25f; + private float dragForce = 0; + + [Header("Strafe")] [SerializeField] - private float strafeForceInAir = 16; + private float strafeForceGrounded = 60; [SerializeField] - private float drag = 6f; + private float strafeForceCrouched = 30; [SerializeField] - private float airDrag = 2f; + private float strafeForceInAir = 16; - private float chosenDrag = 0; + private float strafeForce; + [Header("Jumping")] [SerializeField] private float jumpForce = 10; @@ -52,20 +58,19 @@ public class PlayerMovement : MonoBehaviour private float leapForce = 12.5f; [SerializeField] - private float jumpTimeout = 0.5f; + private float leapTimeout = 0.25f; [SerializeField] - private float leapTimeout = 0.875f; - - private const float MarsGravity = 3.72076f; + private float consecutiveLeapHeightMultiplier = 0.5f; + [SerializeField] + private float consecutiveLeapForwardMultiplier = 1.5f; - private bool canJump = true; + private bool canJumpHigh = true; + [Header("State")] [SerializeField] private float crouchedHeightOffset = 0.3f; - private float localCameraHeight; - [SerializeField] private float airThreshold = 0.4f; @@ -78,6 +83,10 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private Animator animator; + private const float MarsGravity = 3.7f; + + private float localCameraHeight; + private Vector2 aimAngle = Vector2.zero; void Start() @@ -102,23 +111,22 @@ public void SetPlayerInput(InputManager player) private void OnJump(InputAction.CallbackContext ctx) { - if (!(canJump && state == PlayerState.GROUNDED)) + if (!(state == PlayerState.GROUNDED)) return; // Leap jump if (animator.GetBool("Crouching")) { - body.AddForce(Vector3.up * leapForce, ForceMode.VelocityChange); + body.AddForce(Vector3.up * leapForce * (canJumpHigh ? 1f : consecutiveLeapHeightMultiplier), ForceMode.VelocityChange); Vector3 forwardDirection = new Vector3(inputManager.transform.forward.x, 0, inputManager.transform.forward.z); - body.AddForce(forwardDirection * leapForce, ForceMode.VelocityChange); + body.AddForce(forwardDirection * leapForce * (canJumpHigh ? 1f : consecutiveLeapForwardMultiplier), ForceMode.VelocityChange); animator.SetTrigger("Leap"); - StartCoroutine(JumpTimeout(leapTimeout)); + canJumpHigh = false; return; } // Normal jump body.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange); - StartCoroutine(JumpTimeout(jumpTimeout)); } private void SetCrouch(InputAction.CallbackContext ctx) @@ -129,11 +137,10 @@ private void SetCrouch(InputAction.CallbackContext ctx) inputManager.transform.localPosition = new Vector3(inputManager.transform.localPosition.x, localCameraHeight, inputManager.transform.localPosition.z); } - if (ctx.performed) { if (IsInAir()) - return; + return; // TODO: Queue crouch on landing animator.SetBool("Crouching", true); strafeForce = strafeForceCrouched; inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f); @@ -144,15 +151,15 @@ private void SetCrouch(InputAction.CallbackContext ctx) animator.SetBool("Crouching", false); strafeForce = strafeForceGrounded; inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f); + canJumpHigh = true; } } private IEnumerator JumpTimeout(float time) { - canJump = false; yield return new WaitForSeconds(time); - canJump = true; + canJumpHigh = true; } @@ -187,15 +194,19 @@ private void UpdatePosition(Vector3 input) { case PlayerState.IN_AIR: { - chosenDrag = airDrag; + dragForce = airDrag; body.AddForce(input * strafeForceInAir * Time.deltaTime, ForceMode.VelocityChange); body.AddForce(Vector3.down * MarsGravity * Time.deltaTime, ForceMode.Acceleration); - if (!IsInAir()) state = PlayerState.GROUNDED; + if (IsInAir()) + break; + state = PlayerState.GROUNDED; + if (!canJumpHigh) + StartCoroutine(JumpTimeout(leapTimeout)); break; } case PlayerState.GROUNDED: { - chosenDrag = drag; + dragForce = groundDrag; // Walk along ground normal (adjusted if on heavy slope). var groundNormal = GroundNormal(); var direction = Vector3.ProjectOnPlane(input, groundNormal); @@ -211,7 +222,7 @@ private void UpdatePosition(Vector3 input) } } var yDrag = body.velocity.y < 0 ? 0f : body.velocity.y; - body.AddForce(-chosenDrag * body.mass * new Vector3(body.velocity.x, yDrag, body.velocity.z), ForceMode.Force); + body.AddForce(-dragForce * body.mass * new Vector3(body.velocity.x, yDrag, body.velocity.z), ForceMode.Force); } private void UpdateRotation() @@ -228,8 +239,8 @@ private void UpdateRotation() private void UpdateAnimatorParameters() { - animator.SetFloat("Forward", Vector3.Dot(body.velocity, transform.forward) / maxVelocity); - animator.SetFloat("Right", Vector3.Dot(body.velocity, transform.right) / maxVelocity); + animator.SetFloat("Forward", Vector3.Dot(body.velocity, transform.forward) / maxVelocityBeforeExtraDamping); + animator.SetFloat("Right", Vector3.Dot(body.velocity, transform.right) / maxVelocityBeforeExtraDamping); } void OnDrawGizmos() @@ -247,8 +258,11 @@ void FixedUpdate() // Limit velocity when not grounded if (state == PlayerState.GROUNDED) return; - // TODO: clamp the magnitude instead of individual components - body.velocity = new Vector3(Mathf.Clamp(body.velocity.x, -maxVelocity, maxVelocity), body.velocity.y, Mathf.Clamp(body.velocity.z, -maxVelocity, maxVelocity)); + // Add extra drag when player velocity is too high + var maxVelocityReached = Mathf.Abs(body.velocity.x) > maxVelocityBeforeExtraDamping || Mathf.Abs(body.velocity.z) > maxVelocityBeforeExtraDamping; + // TODO: also break if in a consecutive leapjump + if (maxVelocityReached) + body.AddForce(-extraDamping * body.mass * new Vector3(body.velocity.x, 0, body.velocity.z), ForceMode.Force); } void Update() From ddbe762c1a839c840148c0e65fa18cddbd86a944 Mon Sep 17 00:00:00 2001 From: Fredrik Date: Thu, 30 Nov 2023 22:44:10 +0100 Subject: [PATCH 3/6] Add queueable crouching in air for more fluid crouching - Todo: refactor more code to use movement delegate(s) --- .../Scripts/Control&Input/PlayerMovement.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index 975026bf3..4bf49f176 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -61,9 +61,9 @@ public class PlayerMovement : MonoBehaviour private float leapTimeout = 0.25f; [SerializeField] - private float consecutiveLeapHeightMultiplier = 0.5f; + private float dashHeightMultiplier = 0.5f; [SerializeField] - private float consecutiveLeapForwardMultiplier = 1.5f; + private float dashForwardMultiplier = 1.5f; private bool canJumpHigh = true; @@ -89,6 +89,9 @@ public class PlayerMovement : MonoBehaviour private Vector2 aimAngle = Vector2.zero; + private delegate void MovementEvent(); + private MovementEvent onLanding; + void Start() { body = GetComponent(); @@ -117,9 +120,9 @@ private void OnJump(InputAction.CallbackContext ctx) // Leap jump if (animator.GetBool("Crouching")) { - body.AddForce(Vector3.up * leapForce * (canJumpHigh ? 1f : consecutiveLeapHeightMultiplier), ForceMode.VelocityChange); + body.AddForce(Vector3.up * leapForce * (canJumpHigh ? 1f : dashHeightMultiplier), ForceMode.VelocityChange); Vector3 forwardDirection = new Vector3(inputManager.transform.forward.x, 0, inputManager.transform.forward.z); - body.AddForce(forwardDirection * leapForce * (canJumpHigh ? 1f : consecutiveLeapForwardMultiplier), ForceMode.VelocityChange); + body.AddForce(forwardDirection * leapForce * (canJumpHigh ? 1f : dashForwardMultiplier), ForceMode.VelocityChange); animator.SetTrigger("Leap"); canJumpHigh = false; return; @@ -140,10 +143,11 @@ private void SetCrouch(InputAction.CallbackContext ctx) if (ctx.performed) { if (IsInAir()) - return; // TODO: Queue crouch on landing - animator.SetBool("Crouching", true); - strafeForce = strafeForceCrouched; - inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f); + { + onLanding += SetCrouchTrue; + return; + } + SetCrouchTrue(); } if (ctx.canceled) @@ -152,10 +156,18 @@ private void SetCrouch(InputAction.CallbackContext ctx) strafeForce = strafeForceGrounded; inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f); canJumpHigh = true; + onLanding -= SetCrouchTrue; } } + private void SetCrouchTrue() + { + animator.SetBool("Crouching", true); + strafeForce = strafeForceCrouched; + inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f); + } + private IEnumerator JumpTimeout(float time) { yield return new WaitForSeconds(time); @@ -200,8 +212,9 @@ private void UpdatePosition(Vector3 input) if (IsInAir()) break; state = PlayerState.GROUNDED; + onLanding?.Invoke(); if (!canJumpHigh) - StartCoroutine(JumpTimeout(leapTimeout)); + StartCoroutine(JumpTimeout(leapTimeout)); break; } case PlayerState.GROUNDED: From a0915f5a55d4a922a1e2a2bb05087f07c02fc373 Mon Sep 17 00:00:00 2001 From: Fredrik Lillemoen Eiding Date: Fri, 1 Dec 2023 00:39:33 +0100 Subject: [PATCH 4/6] Add crouch queing in air, add dashing with consecutive leaps --- Assets/Prefabs/Input/Player.prefab | 5 +-- .../Scripts/Control&Input/PlayerMovement.cs | 33 ++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Assets/Prefabs/Input/Player.prefab b/Assets/Prefabs/Input/Player.prefab index 3dbd2fe5d..2bf32f020 100644 --- a/Assets/Prefabs/Input/Player.prefab +++ b/Assets/Prefabs/Input/Player.prefab @@ -63,14 +63,15 @@ MonoBehaviour: airDrag: 1 maxVelocityBeforeExtraDamping: 10 extraDamping: 25 + dashDamping: 4 strafeForceGrounded: 60 strafeForceCrouched: 30 strafeForceInAir: 30 jumpForce: 10 leapForce: 12.5 leapTimeout: 0.25 - consecutiveLeapHeightMultiplier: 0.5 - consecutiveLeapForwardMultiplier: 1.5 + dashHeightMultiplier: 0.5 + dashForwardMultiplier: 1 crouchedHeightOffset: 0.8 airThreshold: 0.4 slopeAngleThreshold: 50 diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index 4bf49f176..4bd00d00d 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -62,10 +62,14 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private float dashHeightMultiplier = 0.5f; + [SerializeField] private float dashForwardMultiplier = 1.5f; - private bool canJumpHigh = true; + [SerializeField] + private float dashDamping = 4f; + + private bool isDashing = false; [Header("State")] [SerializeField] @@ -117,17 +121,16 @@ private void OnJump(InputAction.CallbackContext ctx) if (!(state == PlayerState.GROUNDED)) return; - // Leap jump + // Leap/dash jump if (animator.GetBool("Crouching")) { - body.AddForce(Vector3.up * leapForce * (canJumpHigh ? 1f : dashHeightMultiplier), ForceMode.VelocityChange); + body.AddForce(Vector3.up * leapForce * (isDashing ? dashHeightMultiplier : 1f), ForceMode.VelocityChange); Vector3 forwardDirection = new Vector3(inputManager.transform.forward.x, 0, inputManager.transform.forward.z); - body.AddForce(forwardDirection * leapForce * (canJumpHigh ? 1f : dashForwardMultiplier), ForceMode.VelocityChange); + body.AddForce(forwardDirection * leapForce * (isDashing ? dashForwardMultiplier : 1f), ForceMode.VelocityChange); animator.SetTrigger("Leap"); - canJumpHigh = false; + onLanding += EnableDash; return; } - // Normal jump body.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange); } @@ -155,7 +158,7 @@ private void SetCrouch(InputAction.CallbackContext ctx) animator.SetBool("Crouching", false); strafeForce = strafeForceGrounded; inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f); - canJumpHigh = true; + isDashing = false; onLanding -= SetCrouchTrue; } @@ -168,13 +171,18 @@ private void SetCrouchTrue() inputManager.gameObject.LeanMoveLocalY(localCameraHeight - crouchedHeightOffset, 0.2f); } + private void EnableDash() + { + StartCoroutine(JumpTimeout(leapTimeout)); + } + private IEnumerator JumpTimeout(float time) { yield return new WaitForSeconds(time); - canJumpHigh = true; + isDashing = IsInAir(); + onLanding -= EnableDash; } - private bool IsInAir() { // Cast a box to detect (partial) ground. See OnDrawGizmos for what I think is the extent of the box cast. @@ -196,8 +204,6 @@ private Vector3 GroundNormal() return Vector3.up; } - - private void UpdatePosition(Vector3 input) { // Modify input to addforce with relation to current rotation. @@ -213,8 +219,6 @@ private void UpdatePosition(Vector3 input) break; state = PlayerState.GROUNDED; onLanding?.Invoke(); - if (!canJumpHigh) - StartCoroutine(JumpTimeout(leapTimeout)); break; } case PlayerState.GROUNDED: @@ -273,9 +277,8 @@ void FixedUpdate() return; // Add extra drag when player velocity is too high var maxVelocityReached = Mathf.Abs(body.velocity.x) > maxVelocityBeforeExtraDamping || Mathf.Abs(body.velocity.z) > maxVelocityBeforeExtraDamping; - // TODO: also break if in a consecutive leapjump if (maxVelocityReached) - body.AddForce(-extraDamping * body.mass * new Vector3(body.velocity.x, 0, body.velocity.z), ForceMode.Force); + body.AddForce(-(isDashing ? dashDamping : extraDamping) * body.mass * new Vector3(body.velocity.x, 0, body.velocity.z), ForceMode.Force); } void Update() From d0260709e7446280c0115e395d225e11bbbc388c Mon Sep 17 00:00:00 2001 From: Fredrik Lillemoen Eiding Date: Fri, 1 Dec 2023 01:25:41 +0100 Subject: [PATCH 5/6] Add minimum velocity for dash. --- Assets/Prefabs/Input/Player.prefab | 2 +- Assets/Scripts/Control&Input/PlayerMovement.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Assets/Prefabs/Input/Player.prefab b/Assets/Prefabs/Input/Player.prefab index 2bf32f020..188912ef1 100644 --- a/Assets/Prefabs/Input/Player.prefab +++ b/Assets/Prefabs/Input/Player.prefab @@ -63,7 +63,6 @@ MonoBehaviour: airDrag: 1 maxVelocityBeforeExtraDamping: 10 extraDamping: 25 - dashDamping: 4 strafeForceGrounded: 60 strafeForceCrouched: 30 strafeForceInAir: 30 @@ -72,6 +71,7 @@ MonoBehaviour: leapTimeout: 0.25 dashHeightMultiplier: 0.5 dashForwardMultiplier: 1 + dashDamping: 0.5 crouchedHeightOffset: 0.8 airThreshold: 0.4 slopeAngleThreshold: 50 diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index 4bd00d00d..0aad35f21 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -69,6 +69,9 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private float dashDamping = 4f; + [SerializeField] + private float minDashVelocity = 8f; + private bool isDashing = false; [Header("State")] @@ -275,6 +278,13 @@ void FixedUpdate() // Limit velocity when not grounded if (state == PlayerState.GROUNDED) return; + + if (isDashing) + { + var directionalForces = new Vector3(body.velocity.x, 0, body.velocity.z); + if (directionalForces.magnitude < minDashVelocity) + isDashing = false; + } // Add extra drag when player velocity is too high var maxVelocityReached = Mathf.Abs(body.velocity.x) > maxVelocityBeforeExtraDamping || Mathf.Abs(body.velocity.z) > maxVelocityBeforeExtraDamping; if (maxVelocityReached) From e92da4679ce6024e01c881f5fe6ccbc014bdd8bb Mon Sep 17 00:00:00 2001 From: Fredrik Date: Sat, 2 Dec 2023 23:01:07 +0100 Subject: [PATCH 6/6] Fix some function naming --- Assets/Scripts/Control&Input/PlayerMovement.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index 0aad35f21..3ed17f229 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -114,8 +114,8 @@ public void SetPlayerInput(InputManager player) { inputManager = player; inputManager.onSelect += OnJump; - inputManager.onCrouchPerformed += SetCrouch; - inputManager.onCrouchCanceled += SetCrouch; + inputManager.onCrouchPerformed += OnCrouch; + inputManager.onCrouchCanceled += OnCrouch; localCameraHeight = inputManager.transform.localPosition.y; } @@ -138,7 +138,7 @@ private void OnJump(InputAction.CallbackContext ctx) body.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange); } - private void SetCrouch(InputAction.CallbackContext ctx) + private void OnCrouch(InputAction.CallbackContext ctx) { if (LeanTween.isTweening(inputManager.gameObject)) { @@ -150,10 +150,10 @@ private void SetCrouch(InputAction.CallbackContext ctx) { if (IsInAir()) { - onLanding += SetCrouchTrue; + onLanding += StartCrouch; return; } - SetCrouchTrue(); + StartCrouch(); } if (ctx.canceled) @@ -162,12 +162,12 @@ private void SetCrouch(InputAction.CallbackContext ctx) strafeForce = strafeForceGrounded; inputManager.gameObject.LeanMoveLocalY(localCameraHeight, 0.2f); isDashing = false; - onLanding -= SetCrouchTrue; + onLanding -= StartCrouch; } } - private void SetCrouchTrue() + private void StartCrouch() { animator.SetBool("Crouching", true); strafeForce = strafeForceCrouched;