Skip to content

Instantly share code, notes, and snippets.

@gologius
Last active October 15, 2017 11:43
Show Gist options
  • Save gologius/6b9c2eefc11cd4fb3b84fe32012f1b0a to your computer and use it in GitHub Desktop.
Save gologius/6b9c2eefc11cd4fb3b84fe32012f1b0a to your computer and use it in GitHub Desktop.
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