言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Rigidbody.SweepTest

Switch to Manual
public function SweepTest(direction: Vector3, hitInfo: RaycastHit, distance: float = Mathf.Infinity): bool;

Parameters

direction The direction into which to sweep the rigidbody.
hitInfo If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit).
distance The length of the sweep.

Returns

bool True when the rigidbody sweep intersects any collider, otherwise false.

Description

Rigidbodyオブジェクトが特定の方向でオブジェクトと衝突するかテストします

This is similar to doing a Physics.Raycast for all points contained in any of a Rigidbody's colliders and returning the closest of all hits (if any) reported. This is useful for AI code, when you need to know if an object would fit somewhere without colliding with anything. Note that this function only works when a primitive collider type (sphere, cube or capsule) is attached to the rigidbody object - mesh colliders will not work, although they can be detected in the scene by the sweep. See Also: Physics.SphereCast, Physics.CapsuleCast, Rigidbody.SweepTestAll.

	var hit : RaycastHit;

	function Update () {
		// Cast rigidbody shape 10 meters forward, to see if it is about to hit anything
		if (rigidbody.SweepTest (transform.forward, hit, 10)) {
			Debug.Log(hit.distance + "mts distance to obstacle");
		}
	}