Is there any way to move an object forward in Three.js?
Maybe I should convert the rotation.x,y,z to a vector, and deal with it. But I'm beginner, and I don't have any idea how to do it.
Move object (image) with arrow keys using JavaScript function - In this example we will learn how to move object/image using arrow keys (left, top, right and down). We will call function in Body tag on "onkeydown" event, when you will down arrow keys object will be moved on the browser screen.
Click and drag camera. The first issue that needed to be resolved was the click and drag camera movement. Three. js offers a couple of base camera views to get us started.
Object3D has some handy methods for that.
object.translateZ( 10 );
Please use above answer of @mrdoob, creator of ThreeJS:
object.translateZ( delta );
===OLD ANSWER===
A tutorial that worked for older ThreeJS version: http://www.aerotwist.com/tutorials/getting-started-with-three-js/
// set position of YOUR_OBJECT YOUR_OBJECT.position.x = 10; YOUR_OBJECT.position.y = 50; YOUR_OBJECT.position.z = 130;
More options:
var STEP = 10; var newCubeMatrix = cube.matrix; newCubeMatrix.identity(); //newCubeMatrix.multiplySelf(THREE.Matrix4.rotationYMatrix(cube.rotation.y)); newCubeMatrix.multiplySelf(THREE.Matrix4.translationMatrix(cube.position.x, cube.position.y, cube.position.z + STEP)); cube.updateMatrix();
details posted here https://gamedev.stackexchange.com/questions/7490/translate-object-in-world-space-usings-its-local-rotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With