three.js - 使用 Raycast 方法检测玩家是否使用 ThreeJs 和 CannonJs 接地
问题描述
我目前正在尝试实现 FPS 控件并且需要检测玩家是在地面上还是在飞行(或在跳跃)。所以我了解到可以使用 ThreeJs 的 Raycaster 方法来检测这一点。但是我该如何实施这种方法呢?
我的试用:
let DOWN_DIRECTION = new THREE.Vector3(0, -1, 0);
this._rayCaster = new THREE.Raycaster(this._player._mesh.position, DOWN_DIRECTION, 0, 10);
this._rayCaster.set(this._player._mesh.position, DOWN_DIRECTION);
const intersect = this._rayCaster.intersectObjects(this._player._scene.children, true);
执行上述代码段后,我对 intersect 值进行了控制台操作,它返回了一个空数组。
原始输出:[] 空数组
预期输出:地面(平面网格)
使用的模型:平面为地面,长方体为玩家。
我是否遗漏了代码片段中的某些内容以使其正常工作?
解决方案
推荐阅读
- hana - SAP BW\4 HANA 和 SAP 原生 Hana 有什么区别?
- javascript - 尝试将 JavaScript 数组传递给我的 ASP.NET Core 控制器但失败
- ios - 如何快速将任何未定义的变量存储在可编码的结构中
- typescript - 从打字稿界面中提取嵌套字段并将其合并为新类型
- reactjs - 使用方向 rtl 拖动列并调整其大小在 MUI-Datatables 中不起作用
- php - REST API Woocommerce:身份验证
- mongodb - 如何 InsertOne 到 mongo 数据库
- python - Pandas - 是否可以根据其他列中的布尔值创建一个列,将它们视为变量?
- mongodb - Mongodb,获取字段的不同值并将值作为单个文档输出
- oracle - 如何在 Oracle 中安全地引用任意字符串