c# - 如何在不移动盒子的情况下进行 BoxCast()?

标签 c# unity3d collision-detection collider

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

关于c# - 如何在不移动盒子的情况下进行 BoxCast()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51921502/

相关文章:

c# - OpenCSP 失败,错误代码为 2148073494

c# - 获取创建类的对象的实例

c# - 为什么我们在初始化Vector3时使用 "new"关键字,而不是整数?

JAVA:2D 游戏冒险。碰撞检测问题

C# 节流 For 循环

c# - 数据导入 - Excel 到 SQL Azure?

c# - 重启按钮在 Unity 5.6 上不起作用

JavaScript:碰撞检测不起作用

c - 关于 SOIL、OpenGL 和 GLUT 的两个问题

c# - AutoFixture重构