public static bool BoxCast(Vector3 center,
Vector3 halfExtents,
Vector3 direction,
Quaternion orientation = Quaternion.identity,
float maxDistance = Mathf.Infinity,
...);
这些是 Unity3D 中箱播的参数。我对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
(注意:"盒子"不是真实对象(。
你要的是Physics.Overlap^shape^()
. 在您的情况下,OverlapBox 将以数组的形式返回该框中的所有碰撞体。 您需要了解的有关框中对象的任何信息都可以在脚本中解析出来。
请参阅@Frederik Widerberg对OverlapBox链接的回答=(
.有了参数,
_position:即将铸造的立方体的位置
.矢量3(0.5f, 0.5f, 0.5f( : 假设您的单位大小为 1.0
_directionVector:3D 中的投射方向,例如
Vector3 directionVector = _positon - positionWhereFrom (立方体的投射方向(
.Quanion.LookRotation(_directionVector(:以方向为方向
0.0f : 无光线投射距离,就地框****
_movementControlLayerMaskValue:您想要与演员表交互的图层 ex:_movementControlLayerMaskValue = LayerMask.GetMask("Default"(;
Physics.BoxCast(_position,new Vector3(0.5f, 0.5f, 0.5f(,_directionVector, Quanion.LookRotation(_directionVector(,0.0f,_movementControlLayerMaskValue(;