首页 > 解决方案 > 如何沿其在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

标签: three.js

解决方案


我相信您正在寻找car.translateZ(distance);它沿着其局部 z 轴移动对象,而不是全局位置,这意味着它尊重对象的旋转。在 docs 中阅读有关它的更多信息。


推荐阅读