El centroide de la primitiva utilizado para realizar el cast.
When the RaycastHit2D is returned from line or ray casting, the centroid is identical to the return point property. However when using cast methods that use a geometry shape (as opposed to a simple point) such as circle or box casting, the centroid
is the center of the respective shape when it is in contact with the returned point.
El centroid
es útil para determinar la posición en la que la forma cast debe ser para que colisione en el punto de contacto. Tenga en cuenta que el punto tiene en cuenta cualquier rotación especificada para la forma cuando se emitió.
using UnityEngine;
public class Example : MonoBehaviour { // A stationary planet public GameObject planet; // The satellite is moving around the planet public GameObject satellite;
void Update() { RaycastHit2D hit = Physics2D.CircleCast(satellite.transform.position, 10.0f, planet.transform.position);
if (hit.collider != null) { // Draws a line from the planet to the centre of the satellite that was hit as the satellite moves Debug.DrawLine(planet.transform.position, hit.centroid, Color.yellow); } } }
See Also: point, Physics2D.Raycast, Physics2D.Linecast, Physics2D.CircleCast & Physics2D.BoxCast.