From a5b663c838c4b408c07b91adc93f071b93b04a46 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 17 Apr 2020 23:07:27 -0500 Subject: [PATCH] adding isGrounded property --- Assets/Scenes/SampleScene.unity | 14 ++------------ Assets/Scripts/MoveController.cs | 4 ++++ Assets/Scripts/PlayerController.cs | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index dc99e53..dfa6753 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -623,18 +623,8 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, type: 3} - propertyPath: timeToJumpApex - value: 0.97 - objectReference: {fileID: 0} - - target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662, - type: 3} - propertyPath: maxFallSpeed - value: -20 - objectReference: {fileID: 0} - - target: {fileID: 4623847142764859892, guid: b29a944aaba25f643afdc6b049845662, - type: 3} - propertyPath: collisionMask.m_Bits - value: 1024 + propertyPath: timeToMaxRunSpeed + value: 0.15 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: b29a944aaba25f643afdc6b049845662, type: 3} diff --git a/Assets/Scripts/MoveController.cs b/Assets/Scripts/MoveController.cs index 37bb318..cadb5d6 100644 --- a/Assets/Scripts/MoveController.cs +++ b/Assets/Scripts/MoveController.cs @@ -19,6 +19,10 @@ public class MoveController : MonoBehaviour new BoxCollider2D collider; RaycastOrigins raycastOrigins; + public bool isGrounded { + get => collisions.below; + } + void Start() { collider = GetComponent(); CalculateRaySpacing(); diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 1e75b5e..354fdcc 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -38,7 +38,7 @@ public class PlayerController : MonoBehaviour { } float targetX = input.x * moveSpeed; - if (moveController.collisions.below) { + if (moveController.isGrounded) { velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed); } else { velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);