Bonus #2: Flying Controls
If we make a space simulation, weâre going to want to fly through it, right? We can use the same controls that we used to fly through the planets in Chapter 5, âFunctions: Use and Use Againâ. Start by loading the fly controls code collection at the very top of our code:
â | <body></body> |
â | <script src=â"/three.js"â></script> |
» | <script src=â"/controls/FlyControls.js"â></script> |
We will need yet another camera for this. Just below the moon-cam code, add a ship-cam:
â | âvarâ shipCam = ânewâ THREE.PerspectiveCamera(75, aspectRatio, 1, 10000); |
â | shipCam.position.âsetâ(0, 0, 500); |
â | scene.add(shipCam); |
Add the fly controls code just below that. (See The Hitchhikerâs Guide to the Galaxy
Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.