在位置上找到GameObject上的最近

在位置上找到GameObject上的最近

本文介绍了在位置上找到GameObject上的最近/最近点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从悬吊在起重机上的负载中找到吊臂段上的一点,该负载与负载的距离最小,起重机臂受命中BoxCollider,并且我正在使用Physics.overlap方法.

I want to find out a point on boom section from load hanging on crane which have minimum distance from load, crane-Boom having BoxCollider on hit and I am using Physics.overlap method.

如何从源对象中找到GameObject上的最近点?

How do you find a closest point on a GameObject from source object?

[1]:和 Collider.ClosestPointOnBounds .如果您还想检查自定义位置和旋转而不是使用对撞机的位置和旋转,请使用 Physics.ClosestPoint .

[1]: and Collider.ClosestPointOnBounds. If you also want to check for custom position and rotation instead of using the collider's postion and roation then use Physics.ClosestPoint.

其中三个功能的用法示例:

Example usage for 3 of these functions:

public Vector3 sourceObject;
public Collider targetCollider;

// Update is called once per frame
void Update()
{
    //Method 1
    Vector3 closestPoint = targetCollider.ClosestPoint(sourceObject);

    //Method 2
    Vector3 closestPointInBounds = targetCollider.ClosestPointOnBounds(sourceObject);

    //Method 3
    Vector3 pos = targetCollider.transform.position;
    Quaternion rot = targetCollider.transform.rotation;
    Vector3 closestPointCollider = Physics.ClosestPoint(sourceObject, targetCollider, pos, rot);
}

这篇关于在位置上找到GameObject上的最近/最近点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:46