Create a gist now

Instantly share code, notes, and snippets.

@nbriz /lookAt.js Secret
Last active Dec 18, 2015

What would you like to do?
keep camera looking at a mesh, for threejs_playGnd
/* ------------------- INSTRUCTIONS -----
to keep your camera focused on a mesh
when the camera is moving and/or when
the mesh is moving, add the code below
to your draw() function
-------------------------------------- */
camera.lookAt(mesh.position);
/* --------------------------------------
to see this in action add motion to your
object, add the code below to your draw()
-------------------------------------- */
mesh.position.y = Math.sin( Date.now() * 0.002 ) * 450;
/* --------------------------------------
to get a sense of the space you can add a
slightly tilted plane in your setup()
-------------------------------------- */
wgeometry = new THREE.PlaneGeometry( 1000, 1000, 100, 100 );
wmaterial = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, wireframeLinewidth: 1 } );
wireplane = new THREE.Mesh( wgeometry, wmaterial );
wireplane.rotation.x = - Math.PI / 3;
scene.add( wireplane );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment