如何在不移动盒子的情况下进行 BoxCast()?
How to BoxCast() without moving the box?
public static bool BoxCast(Vector3 center,
Vector3 halfExtents,
Vector3 direction,
Quaternion orientation = Quaternion.identity,
float maxDistance = Mathf.Infinity,
...);
这些是 Unity3D 中 boxcast 的参数。我对 maxDistance
参数的用途感到困惑,因为我们已经使用 halfExtents
参数绘制了框。如果我不想移动盒子怎么办?即,我想画一个盒子并获取有关其中任何内容的信息。我不想移动盒子。使用 maxDistance = 0
似乎什么都不做,因为它没有记录任何命中。使用 maxDistance > 0
会移动盒子,我希望避免这种情况。
如何使用 BoxCast(),避免移动盒子?
有Physics.OverlapBox
,也许那个更适合您的需要?
public static Collider[] OverlapBox(Vector3 center, Vector3 halfExtents,
Quaternion orientation = Quaternion.identity,
int layerMask = AllLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html
或者甚至 Physics.CheckBox
如果您不关心盒子里的实际情况。
https://docs.unity3d.com/ScriptReference/Physics.CheckBox.html
任何 Physics.^shape^Cast()
调用都只是具有维度的光线投射。在你的例子中,BoxCast 沿着射线推动一个盒子并检查它与什么相交,直到 maxDistance
(注意:'box' 不是真实的对象)。
您要的是Physics.Overlap^shape^()
。在您的情况下,OverlapBox 将 return 该框中的所有碰撞器作为数组。您需要了解有关框中对象的任何信息,然后可以在脚本中解析出来。
OverlapBox 链接见@Frederik Widerberg's =)
。带参数,
。 _position: 即将被施放的立方体的位置
。 Vector3(0.5f, 0.5f, 0.5f) :假设您的单位 cude 大小为 1.0
。 _directionVector:演员在 3D 中的方向,例如
Vector3 directionVector = _positon - positionWhereFrom(立方体的投射方向)
。 Quaternion.LookRotation(_directionVector): 以方向为方向
。 0.0f : 没有光线投射距离,在 place box ****
。 _movementControlLayerMaskValue :你想要与演员互动的图层
ex:_movementControlLayerMaskValue = LayerMask.GetMask("默认");
Physics.BoxCast(_position,new Vector3(0.5f, 0.5f, 0.5f),_directionVector, Quaternion.LookRotation(_directionVector),0.0f,_movementControlLayerMaskValue);
public static bool BoxCast(Vector3 center,
Vector3 halfExtents,
Vector3 direction,
Quaternion orientation = Quaternion.identity,
float maxDistance = Mathf.Infinity,
...);
这些是 Unity3D 中 boxcast 的参数。我对 maxDistance
参数的用途感到困惑,因为我们已经使用 halfExtents
参数绘制了框。如果我不想移动盒子怎么办?即,我想画一个盒子并获取有关其中任何内容的信息。我不想移动盒子。使用 maxDistance = 0
似乎什么都不做,因为它没有记录任何命中。使用 maxDistance > 0
会移动盒子,我希望避免这种情况。
如何使用 BoxCast(),避免移动盒子?
有Physics.OverlapBox
,也许那个更适合您的需要?
public static Collider[] OverlapBox(Vector3 center, Vector3 halfExtents,
Quaternion orientation = Quaternion.identity,
int layerMask = AllLayers,
QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html
或者甚至 Physics.CheckBox
如果您不关心盒子里的实际情况。
https://docs.unity3d.com/ScriptReference/Physics.CheckBox.html
任何 Physics.^shape^Cast()
调用都只是具有维度的光线投射。在你的例子中,BoxCast 沿着射线推动一个盒子并检查它与什么相交,直到 maxDistance
(注意:'box' 不是真实的对象)。
您要的是Physics.Overlap^shape^()
。在您的情况下,OverlapBox 将 return 该框中的所有碰撞器作为数组。您需要了解有关框中对象的任何信息,然后可以在脚本中解析出来。
OverlapBox 链接见@Frederik Widerberg's
。带参数,
。 _position: 即将被施放的立方体的位置
。 Vector3(0.5f, 0.5f, 0.5f) :假设您的单位 cude 大小为 1.0
。 _directionVector:演员在 3D 中的方向,例如
Vector3 directionVector = _positon - positionWhereFrom(立方体的投射方向)
。 Quaternion.LookRotation(_directionVector): 以方向为方向
。 0.0f : 没有光线投射距离,在 place box ****
。 _movementControlLayerMaskValue :你想要与演员互动的图层 ex:_movementControlLayerMaskValue = LayerMask.GetMask("默认");
Physics.BoxCast(_position,new Vector3(0.5f, 0.5f, 0.5f),_directionVector, Quaternion.LookRotation(_directionVector),0.0f,_movementControlLayerMaskValue);