4

I'm trying to get a 'chase' camera working on an object.

I've found an example that doe exactly what I want, however it is aimed at r49:

http://stemkoski.github.com/Three.js/Chase-Camera.html

I've attempted to update it to the new rotation methods as follows:

var rotation_matrix = new THREE.Matrix4().makeRotationZ(rotateAngle); cube.matrix.multiplySelf(rotation_matrix); cube.rotation.setEulerFromRotationMatrix(cube.matrix);

This seems to work fine for the object, however the camera doesn't follow in the same way. I've put up a demo here:

http://jsfiddle.net/SSEDs/

(Press A and D to rotate)

What am I doing wrong?

1
  • Thanks for the pointer, forgot to accept on old questions! Commented Oct 21, 2012 at 17:47

1 Answer 1

16

You need to add the camera as a child of the cube. Not only does it work, but the math is a lot simpler.

cube.add( camera );
Sign up to request clarification or add additional context in comments.

2 Comments

But, when the mesh rotates so does the camera. What if we only wanted to rotate the mesh itself?
@majidarif scene.add( group ); group.add( mesh ); group.add( offset ); offset.add( camera ); group.position controls the mesh's and camera's position. mesh.rotation controls the mesh`s rotation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.