Last active
October 15, 2017 11:43
-
-
Save gologius/6b9c2eefc11cd4fb3b84fe32012f1b0a to your computer and use it in GitHub Desktop.
This file contains 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
public CapsuleCollider capCollider; | |
void Start() | |
{ | |
capColider = this.GetComponent<CapsuleCollider>(); | |
} | |
private bool checkGround() | |
{ | |
//CapsuleColliderの足元に、判定Sphereを設置→Sphere内のオブジェクトを全走査する | |
Vector3 sphereCenter = (this.transform.position + capColider.center) - new Vector3(0f, capColider.height / 2f, 0f); | |
Collider[] colliders = Physics.OverlapSphere(sphereCenter, capColider.radius-0.2f); //CapsuleColliderより小さくしないと壁に当たっとき着地判定が出る | |
foreach (var col in colliders) | |
{ | |
Debug.Log(col.name); | |
return true; //ここでcol.gameObjectなんかを使って適当に判定する | |
} | |
return false; | |
} | |
//SphereCenterデバッグ用 | |
void OnDrawGizmos() | |
{ | |
if (capColider != null) | |
{ | |
Vector3 sphereCenter = (this.transform.position + capColider.center) - new Vector3(0f, capColider.height / 2f, 0f); | |
Gizmos.DrawWireSphere(sphereCenter, capColider.radius); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment