Created
November 23, 2016 00:37
-
-
Save Arakade/6699fa974328d5c1b904be74f0e33532 to your computer and use it in GitHub Desktop.
Patch to WIPController to account for scaling and allow SphereCast for grounded check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.../VR-Step/Scripts/WIPController.cs | 28 ++++++++++++++++++++-- | |
1 file changed, 26 insertions(+), 2 deletions(-) | |
diff --git a/Assets/VR-Step/Scripts/WIPController.cs b/Assets/VR-Step/Scripts/WIPController.cs | |
index 2138c61..fa6e828 100644 | |
--- a/Assets/VR-Step/Scripts/WIPController.cs | |
+++ b/Assets/VR-Step/Scripts/WIPController.cs | |
@@ -60,6 +60,12 @@ namespace VRStep | |
[Tooltip("Threshold on the accelerometer in the up direction of when to detect a jump")] | |
public float jumpDetectionThreshold = 1; | |
+ [Tooltip("How far to raycast to check player is grounded.")] | |
+ public float groundCheckDistance = 0.95f; | |
+ | |
+ [Tooltip("How wide a sphere to cast to check player is grounded. (0 or less = raycast)")] | |
+ public float groundCheckRadius = 0f; | |
+ | |
[Tooltip("Whether or not the character is currently on the ground")] | |
public bool onGround = false; | |
@@ -185,7 +191,7 @@ namespace VRStep | |
void CheckIfOnGround() | |
{ | |
- if (Physics.Raycast(transform.position, Vector3.down, .95f, groundLayerMask)) | |
+ if (castForGround()) | |
{ | |
_jumpGracePeriodTimer = jumpGracePeriod; | |
onGround = true; | |
@@ -199,6 +205,18 @@ namespace VRStep | |
} | |
} | |
+ private bool castForGround() | |
+ { | |
+ if (0f >= groundCheckRadius) | |
+ { | |
+ return Physics.Raycast(transform.position, Vector3.down, transform.localScale.y * groundCheckDistance, groundLayerMask); | |
+ } | |
+ else | |
+ { | |
+ return Physics.SphereCast(new Ray(transform.position, Vector3.down), groundCheckRadius * transform.localScale.y, transform.localScale.y * groundCheckDistance, groundLayerMask); | |
+ } | |
+ } | |
+ | |
@@ -216,7 +234,13 @@ namespace VRStep | |
dampingEnabled = false; | |
} | |
} | |
- | |
+ | |
+ private void OnDrawGizmosSelected() { | |
+ Gizmos.DrawRay(transform.position, Vector3.down * groundCheckDistance * transform.localScale.y); | |
+ if (0f < groundCheckRadius) { | |
+ Gizmos.DrawWireSphere(transform.position + Vector3.down * groundCheckDistance * transform.localScale.y, groundCheckRadius * transform.localScale.y); | |
+ } | |
+ } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment