| point1 | カプセルの start にある球形の中心 |
| point2 | カプセルの end にある球形の中心 |
| radius | カプセルの半径 |
| direction | カプセル型の通過方向 |
| maxDistance | スイープの最大の長さ。 |
| layerMask | レイヤーマスク はレイキャストするときに選択的に衝突を無視するために使用します。 |
| queryTriggerInteraction | トリガーに設定されているものも検索対象にするか |
bool レイが任意のコライダーと交わる場合は true、それ以外は false
カプセル型のレイを飛ばし、オブジェクトコライダーの付いたオブジェクトがヒットするかを調べます
カプセルは2つの終点である point1 と point2 、それらの radius からなる2つの球形で定義されます。
カプセル型が direction に沿って移動していた場合、 hits にはカプセルに衝突する最初のコライダーが返されます。
この関数はキャラクターなど、どこかに移動できる特定の大きさを持つオブジェクトを何にも衝突させずに見つけたいために Raycast で十分な精度を得られない場合に有効です。
注意: CapsuleCast はその原点がコライダーの内側にある場合そのコライダーを検知しません。
If you move colliders from scripting or by animation, there needs to be at
物理ライブラリが更新できるように CapsuleCast が新しい位置に当たる前に
CapsuleCast が新しい位置で当たる前に
See Also: Physics.SphereCast, Physics.CapsuleCastAll, Physics.Raycast, Rigidbody.SweepTest.
function Update () {
var hit : RaycastHit;
var charContr : CharacterController = GetComponent.<CharacterController>();
var p1 : Vector3 = transform.position + charContr.center +
Vector3.up * (-charContr.height*0.5);
var p2 : Vector3 = p1 + Vector3.up * charContr.height;
// Cast character controller shape 10 meters forward to see if it is about to hit anything
if (Physics.CapsuleCast (p1, p2, charContr.radius, transform.forward, hit, 10)) {
distanceToObstacle = hit.distance;
}
}
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void Update() { RaycastHit hit; CharacterController charContr = GetComponent<CharacterController>(); Vector3 p1 = transform.position + charContr.center + Vector3.up * -charContr.height * 0.5F; Vector3 p2 = p1 + Vector3.up * charContr.height; float distanceToObstacle = 0; // Cast character controller shape 10 meters forward to see if it is about to hit anything. if (Physics.CapsuleCast(p1, p2, charContr.radius, transform.forward, out hit, 10)) distanceToObstacle = hit.distance; } }
| point1 | カプセルの start にある球形の中心 |
| point2 | カプセルの end にある球形の中心 |
| radius | カプセルの半径 |
| direction | カプセル型の通過方向 |
| maxDistance | スイープの最大の長さ。 |
| hitInfo | もし true が返されると hitInfo にはコライダーのヒットに関する詳細情報が含まれるようになります。(関連項目: RaycastHit) |
| layerMask | レイヤーマスク はレイキャストするときに選択的に衝突を無視するために使用します。 |
| queryTriggerInteraction | トリガーに設定されているものも検索対象にするか |