Version: 2017.2
public bool SweepTest (Vector3 direction, out RaycastHit hitInfo, float maxDistance= Mathf.Infinity, QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);

パラメーター

direction リジッドボディをスイープする方向。
hitInfo true が返されたときhitInfo はヒットしたコライダーについての情報が含まれています。(関連項目: RaycastHit)
maxDistance スイープの長さ。
queryTriggerInteraction トリガーに設定されているものも検索対象にするか

戻り値

bool リジッドボディが他のコライダーを横切ってスイープする場合は true を返します。その他の場合は false を返します。

説明

Rigidbody オブジェクトが特定の方向でオブジェクトと衝突するかテストします

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.

この関数はプリミティブコライダー型(球、キューブまたはカプセル)や凹面メッシュがリジッドボディオブジェクトにアタッチされている場合にのみ動作することに注意してください。つまり、メッシュコライダーはスイープによってシーン内で検知することはできますが、動作はしません。

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