admin管理员组文章数量:1026653
Like in lots of other similar questions, I want to move an object forward in three.js
based on its rotation. The difference is, I can't use object.translateZ. This is because I'm using a physics simulator and it will mess up if I update the object like that. Here is an example fiddle of my problem. Feel free to play around with my fiddle and add your updated version to your answer.
I would like the cube to move forward by updating mesh.position.x
and mesh.position.z
based on mesh.rotation.y
.
To keep in mind, I've sometimes realized that three.js
rotations are a little weird some times when accessing them using mesh.rotation.y
.
Thanks!
Like in lots of other similar questions, I want to move an object forward in three.js
based on its rotation. The difference is, I can't use object.translateZ. This is because I'm using a physics simulator and it will mess up if I update the object like that. Here is an example fiddle of my problem. Feel free to play around with my fiddle and add your updated version to your answer.
I would like the cube to move forward by updating mesh.position.x
and mesh.position.z
based on mesh.rotation.y
.
To keep in mind, I've sometimes realized that three.js
rotations are a little weird some times when accessing them using mesh.rotation.y
.
Thanks!
Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked Jan 16, 2017 at 5:58 Griffin M.Griffin M. 1961 silver badge17 bronze badges2 Answers
Reset to default 6I would suggest using the mesh.getWorldDirection() to get a direction where you want to move your mesh. Then you can multiply it with a scalar to adjust movement speed.
direction = mesh.getWorldDirection();
mesh.position.add(direction.multiplyScalar(moveSpeed));
Fiddle: https://jsfiddle/k1swrxjr/1/
Good luck!
To move your mesh simply increment the value of the position in which you want your mesh to go in you animate() function instead of init function, example as follows:
function animate() {
mesh.position.x += 0.1;
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
This example code will increase x position of your mesh by 0.1 every time animate() is run.
Like in lots of other similar questions, I want to move an object forward in three.js
based on its rotation. The difference is, I can't use object.translateZ. This is because I'm using a physics simulator and it will mess up if I update the object like that. Here is an example fiddle of my problem. Feel free to play around with my fiddle and add your updated version to your answer.
I would like the cube to move forward by updating mesh.position.x
and mesh.position.z
based on mesh.rotation.y
.
To keep in mind, I've sometimes realized that three.js
rotations are a little weird some times when accessing them using mesh.rotation.y
.
Thanks!
Like in lots of other similar questions, I want to move an object forward in three.js
based on its rotation. The difference is, I can't use object.translateZ. This is because I'm using a physics simulator and it will mess up if I update the object like that. Here is an example fiddle of my problem. Feel free to play around with my fiddle and add your updated version to your answer.
I would like the cube to move forward by updating mesh.position.x
and mesh.position.z
based on mesh.rotation.y
.
To keep in mind, I've sometimes realized that three.js
rotations are a little weird some times when accessing them using mesh.rotation.y
.
Thanks!
Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked Jan 16, 2017 at 5:58 Griffin M.Griffin M. 1961 silver badge17 bronze badges2 Answers
Reset to default 6I would suggest using the mesh.getWorldDirection() to get a direction where you want to move your mesh. Then you can multiply it with a scalar to adjust movement speed.
direction = mesh.getWorldDirection();
mesh.position.add(direction.multiplyScalar(moveSpeed));
Fiddle: https://jsfiddle/k1swrxjr/1/
Good luck!
To move your mesh simply increment the value of the position in which you want your mesh to go in you animate() function instead of init function, example as follows:
function animate() {
mesh.position.x += 0.1;
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
This example code will increase x position of your mesh by 0.1 every time animate() is run.
本文标签: javascriptThreejs Move object forward without translateZStack Overflow
版权声明:本文标题:javascript - Three.js Move object forward without translateZ - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745649406a2161221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论