Skip to content

Instantly share code, notes, and snippets.

@nbriz

nbriz/lookAt.js Secret

Last active December 18, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbriz/65bca341f3b7eadb2874 to your computer and use it in GitHub Desktop.
Save nbriz/65bca341f3b7eadb2874 to your computer and use it in GitHub Desktop.
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