0
votes

I'm pretty new to three.js.i want to make a cube/object moving in a plain surface/road.i move the object z direction.but i want to move camera too .(like a driver and car).

function move() {
   // move cube and camera
   cube.position.z -= 0.06;
   camera.position.z -= 0.06;
}

As in following picture it start correctly but suddenly rotate and change the direction.basically i expect cube move with camera behind it.so it should look like a car moving with driver in a road.but you can see world is rotating around x axis.i don't want it to rotate like this.i want to know why this is happening.

here is a jsfiddle live example

enter image description here

1

1 Answers

1
votes

You're not telling your camera where you want it to look, so it's remaining pointed at the same target it started out with. If you want it to track the cube in your example, update your move() function to look like:

function move() {
   cube.position.z -= 0.06;
   camera.position.z -= 0.06;
   camera.lookAt(cube);
}