three.js - 如何沿其在three.js中指向的方向向前移动3d对象
问题描述
我在我的three.js 世界中有一辆3d 汽车 我想在它旋转后将它朝它指向的方向移动
//onkeydown forward
car.position.z -= 0.02;//low number since it updates around 60 fps
//onkeydown backword
car.position.z += 0.02;
//onkeydown right
it goes forward and backword but not in the direction its pointing it goes on z axis
解决方案
我相信您正在寻找car.translateZ(distance);
它沿着其局部 z 轴移动对象,而不是全局位置,这意味着它尊重对象的旋转。在 docs 中阅读有关它的更多信息。
推荐阅读
- c++ - c++ set const char* 类的成员变量
- django - 无法将数据添加到 django ManyToManyfield
- python - 如何在 PyQt5 Python 中更改 QMessageBox 的颜色
- linux - 清除输入缓冲区组件 x86 (NASM)
- javascript - 使用 CompletableFuture 在 Java 8 中将 Javascript 包装回调作为 Promise 等效项
- c# - MouseEnter 和 MouseLeave 使按钮在不应隐藏时消失
- assembly - '。' 尝试运行汇编代码时无法识别?
- rabbitmq - 我们如何根据环境交替使用@RabbitListener 和@JMSListener?
- python-3.x - 如何从字符串中提取准确的单词,同时减少误报发现
- django - 如何显示来自用户(django)的文章?