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. |
Tests if a rigidbody would collide with anything, if it was moved through the scene.
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"); } }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { public RaycastHit hit; void Update() { if (rigidbody.SweepTest(transform.forward, out hit, 10)) Debug.Log(hit.distance + "mts distance to obstacle"); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): public hit as RaycastHit def Update() as void: if rigidbody.SweepTest(transform.forward, , 10): Debug.Log((hit.distance + 'mts distance to obstacle'))