Last active
January 12, 2020 12:31
-
-
Save caramelchocolate/af679883f1ebfb2724a6b51a6c3864be to your computer and use it in GitHub Desktop.
Compute CapsuleCollider2D position(x) center
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
using UnityEngine; | |
public class DebugGizmos : MonoBehaviour { | |
void OnDrawGizmos() { | |
float halfWidth = GetComponent<SpriteRenderer>().bounds.extents.x; | |
float halfHeight = GetComponent<SpriteRenderer>().bounds.extents.y; | |
CapsuleCollider2D capsuleCollider2D = GetComponent<CapsuleCollider2D>(); | |
Vector3 capsuleColliderCenter = transform.position + (transform.right * capsuleCollider2D.offset.x * transform.localScale.x); | |
Vector3 capsuleColliderBottom = capsuleColliderCenter - (transform.up * halfHeight); | |
Vector3 capsuleColliderBottomLeft = capsuleColliderBottom - (transform.right * halfWidth); | |
Vector3 capsuleColliderBottomRight = capsuleColliderBottom + (transform.right * halfWidth); | |
Gizmos.color = Color.cyan; | |
// Compute CapsuleCollider2D position(x) center | |
Gizmos.DrawLine(capsuleColliderCenter, capsuleColliderBottom); | |
// IsGrounded | |
Gizmos.DrawLine(capsuleColliderBottomLeft + (transform.right * 0.3f), capsuleColliderBottom - (transform.up * 0.1f)); | |
Gizmos.DrawLine(capsuleColliderBottomRight - (transform.right * 0.3f), capsuleColliderBottom - (transform.up * 0.1f)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment