-
-
Save nbriz/65bca341f3b7eadb2874 to your computer and use it in GitHub Desktop.
keep camera looking at a mesh, for threejs_playGnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------- 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