Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

Rigidbody.SweepTest

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public function SweepTest(direction: Vector3, out hitInfo: RaycastHit, maxDistance: float = Mathf.Infinity, queryTriggerInteraction: QueryTriggerInteraction = QueryTriggerInteraction.UseGlobal): bool;
public bool SweepTest(Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

Parámetros

direction La posición del rigidbody.
hitInfo If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit).
maxDistance The length of the sweep.
queryTriggerInteraction Specifies whether this query should hit Triggers.

Valor de retorno

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

Descripción

Tests if a rigidbody would collide with anything, if it was moved through the scene.

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, say if you need to know that an object would fit through a gap without colliding with anything.

Note that this function only works when a primitive collider type (sphere, cube or capsule) or a convex mesh is attached to the rigidbody object - concave mesh colliders will not work, although they can be detected in the scene by the sweep.

See Also: Physics.SphereCast, Physics.CapsuleCast, Rigidbody.SweepTestAll.


        
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float collisionCheckDistance; public bool aboutToCollide; public float distanceToCollision; public Rigidbody rb;

void Start() { rb = GetComponent<Rigidbody>(); }

void Update() { RaycastHit hit; if (rb.SweepTest (transform.forward, out hit, collisionCheckDistance)) { aboutToCollide = true; distanceToCollision = hit.distance; } } }