Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera following an objects rotation

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?

like image 670
Luca Spiller Avatar asked Dec 06 '22 11:12

Luca Spiller


1 Answers

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 );
like image 126
WestLangley Avatar answered Jan 09 '23 00:01

WestLangley