Version: 2020.3
言語: 日本語
public Vector2 centroid ;

説明

キャストに使用されるプリミティブの重心

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.

centroid は、接触点と重心からキャストする形状の位置を把握するのに便利です。キャストしたときに、位置は指定した形状の回転も考慮しなければいけないことに注意してください。

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); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961