origin | El centro de la esfera al principio del barrido. |
radius | The radius of the sphere. |
direction | La dirección en la cual barrer la esfera. |
hitInfo | Si true se devuelve, hitInfo contendrá más información acerca de dónde el collider ha golpeado (See Also: RaycastHit). |
maxDistance | La longitud máxima de la emisión. |
layerMask | Una Layer mask que es utilizada para ignorar colliders selectivamente cuando se emita una cápsula. |
queryTriggerInteraction | Especifica si esta consulta debería golpear Triggers. |
bool True cuando el barrido de la esfera intersecta cualquier collider, de lo contrario false.
Emite una esfera a lo largo de un rayo y retorna información detallada sobre qué fue hit (golpeado).
This is useful when a Raycast does not give enough precision, because you want to find out if an object of a specific size,
such as a character, will be able to move somewhere without colliding with anything on the way.
Think of the sphere cast like a thick raycast. In this case the ray is specified by a start vector and a
direction.
Notes: SphereCast will not detect colliders for which the sphere overlaps the collider.
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.
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { CharacterController charCtrl; void Start() { charCtrl = GetComponent<CharacterController>(); } void Update() { RaycastHit hit;
Vector3 p1 = transform.position + charCtrl.center; float distanceToObstacle = 0; // Cast a sphere wrapping character controller 10 meters forward // to see if it is about to hit anything. if (Physics.SphereCast(p1, charCtrl.height / 2, transform.forward, out hit, 10)) { distanceToObstacle = hit.distance; } } }
ray | El punto inicial y dirección del rayo en la que se ejecuta el barrido de la esfera. |
radius | The radius of the sphere. |
maxDistance | La longitud máxima de la emisión. |
layerMask | Una Layer mask que es utilizada para ignorar colliders selectivamente cuando se emita una cápsula. |
queryTriggerInteraction | Especifica si esta consulta debería golpear Triggers. |
bool True cuando el barrido de la esfera intersecta cualquier collider, de lo contrario false.
Emite una esfera a lo largo de un rayo y retorna información detallada sobre qué fue hit (golpeado).
This is useful when a Raycast does not give enough precision, because you want to find out if an object of a specific size,
such as a character, will be able to move somewhere without colliding with anything on the way.
Think of the sphere cast like a thick raycast.
Nota: Si usted mueve colliders desde scripting o por animación, necesita haber al menos un FixedUpdate ejecutado para que la librería de física pueda actualizar sus estructuras de datos, antes de que un SphereCast golpeé el collider en su nueva posición.
See Also: Physics.SphereCastAll, Physics.CapsuleCast, Physics.Raycast, Rigidbody.SweepTest.
ray | El punto inicial y dirección del rayo en la que se ejecuta el barrido de la esfera. |
radius | The radius of the sphere. |
hitInfo | Si true se devuelve, hitInfo contendrá más información acerca de dónde el collider ha golpeado (See Also: RaycastHit). |
maxDistance | La longitud máxima de la emisión. |
layerMask | Una Layer mask que es utilizada para ignorar colliders selectivamente cuando se emita una cápsula. |
queryTriggerInteraction | Especifica si esta consulta debería golpear Triggers. |