- AddExplosionForce
- AddForceAtPosition
- AddForce
- AddRelativeForce
- AddRelativeTorque
- AddTorque
- angularDrag
- angularVelocity
- centerOfMass
- ClosestPointOnBounds
- collisionDetectionMode
- detectCollisions
- drag
- freezeRotation
- GetPointVelocity
- GetRelativePointVelocity
- inertiaTensorRotation
- inertiaTensor
- interpolation
- isKinematic
- IsSleeping
- mass
- maxAngularVelocity
- MovePosition
- MoveRotation
- OnCollisionEnter
- OnCollisionExit
- OnCollisionStay
- position
- rotation
- SetDensity
- sleepAngularVelocity
- sleepVelocity
- Sleep
- solverIterationCount
- SweepTestAll
- SweepTest
- useConeFriction
- useGravity
- velocity
- WakeUp
- worldCenterOfMass
Rigidbody.SweepTest 扫描测试
function SweepTest (direction : Vector3, out hitInfo : RaycastHit, distance : float = Mathf.Infinity) : bool
Parameters参数
-
directionThe direction into which to sweep the rigidbody.
扫描刚体的方向 -
hitInfoIf true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit).
如果返回true,hitInfo将包含更多碰撞器碰撞的信息 -
distanceThe length of the sweep
扫描的长度。
bool - True when the rigidbody sweep intersects any collider, otherwise false.
返回bool类型,当为true时,刚体扫描相交的任意碰撞器,否则为false。
Description描述
Tests if a rigidbody would collide with anything, if it was moved through the scene.
如果一个刚体碰到任何东西触发测试,如果它是穿过场景。
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.
这类似于为任何一个刚体的碰撞器包含的所有点做一个Physics.Raycast,并返回最接近的所有碰撞(如果有)报告。这对于AI代码非常有用,当你需要知道如果一个物体想要适配不与任何东西碰撞的地方。
参见: Physics.SphereCast, Physics.CapsuleCast, Rigidbody.SweepTestAll
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public RaycastHit hit;
void Update() {
if (rigidbody.SweepTest(transform.forward, ref hit, 10))
Debug.Log(hit.distance + "mts distance to obstacle");
}
}
var hit : RaycastHit;
function Update () {
// Cast rigidbody shape 10 meters forward, to see if it is about to hit anything
//投下一个刚体向前10米,看它是否将要撞上任何东西
if (rigidbody.SweepTest (transform.forward, hit, 10)) {
Debug.Log(hit.distance + "mts distance to obstacle");
}
}