Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Physics.SphereCast

マニュアルに切り替える
public static function SphereCast(origin: Vector3, radius: float, direction: Vector3, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(origin: Vector3, radius: float, direction: Vector3, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(origin: Vector3, radius: float, direction: Vector3, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(origin: Vector3, radius: float, direction: Vector3, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;

パラメーター

origin 球形が通過を開始する地点の中心
radius 球形の半径
direction 球を通過させる方向
hitInfo もし true が返されると hitInfo にはコライダーのヒットに関する詳細情報が含まれるようになります。(関連項目: RaycastHit)
maxDistance キャストの最大の長さ
layerMask レイヤーマスク はレイキャストするときに選択的に衝突を無視するために使用します。
queryTriggerInteraction トリガーに設定されているものも検索対象にするか

戻り値

bool レイが任意のコライダーと交わる場合は true、それ以外は false

説明

球体のレイを飛ばし、オブジェクトコライダーの付いたオブジェクトがヒットするかを調べ、ヒットしたら詳細情報を返します

この関数はキャラクターなど、どこかに移動できる特定の大きさを持つオブジェクトを何にも衝突させずに見つけたいために Raycast で十分な精度を得られない場合に有効です。 SphereCast は厚みのある Raycast のようなものです。この場合、レイは初期ベクトルと方向を指定します。

注意: SphereCast はその原点がコライダーの内側にある場合そのコライダーを検知しません。
If you move colliders from scripting or by animation, there needs to be at least one FixedUpdate executed so that the physics library can update it's data structures, before a SphereCast will hit the collider at it's new position.

See Also: Physics.SphereCastAll, Physics.CapsuleCast, Physics.Raycast, Rigidbody.SweepTest.

#pragma strict
var charCtrl: CharacterController;
function Start() {
	charCtrl = GetComponent.<CharacterController>();
}
function Update() {
	var hit: RaycastHit;
	var p1: Vector3 = transform.position + charCtrl.center;
	var distanceToObstacle: float = 0;
	// to see if it is about to hit anything.
	if (Physics.SphereCast(p1, charCtrl.height / 2, transform.forward, hit, 10)) {
		distanceToObstacle = hit.distance;
	}
}

public static function SphereCast(ray: Ray, radius: float, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;

パラメーター

ray レイの始点と方向
radius 球形の半径
maxDistance キャストの最大の長さ
layerMask レイヤーマスク はレイキャストするときに選択的に衝突を無視するために使用します。
queryTriggerInteraction トリガーに設定されているものも検索対象にするか

戻り値

bool レイが任意のコライダーと交わる場合は true、それ以外は false

説明

球体のレイを飛ばし、オブジェクトコライダーの付いたオブジェクトがヒットするかを調べ、ヒットしたら詳細情報を返します

この関数はキャラクターなど、どこかに移動できる特定の大きさを持つオブジェクトを何にも衝突させずに見つけたいために Raycast で十分な精度を得られない場合に有効です。 SphereCast は厚みのある Raycast のようなものです。

注意: コライダーをスクリプトやアニメーションで移動させる場合、物理ライブラリが更新できるように SphereCast が新しい位置に当たる前に最低でも1度 FixedUpdate が実行されている必要があります。

See Also: Physics.SphereCastAll, Physics.CapsuleCast, Physics.Raycast, Rigidbody.SweepTest.


public static function SphereCast(ray: Ray, radius: float, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public static function SphereCast(ray: Ray, radius: float, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;

パラメーター

ray レイの始点と方向
radius 球形の半径
hitInfo もし true が返されると hitInfo にはコライダーのヒットに関する詳細情報が含まれるようになります。(関連項目: RaycastHit)
maxDistance キャストの最大の長さ
layerMask レイヤーマスク はレイキャストするときに選択的に衝突を無視するために使用します。
queryTriggerInteraction トリガーに設定されているものも検索対象にするか

説明