Advertisement
yskang

threejs-minecraft-41

Apr 28th, 2020 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in index.js
  2. (function() {
  3.     // ... other code snippet
  4.  
  5.     // Find this codes for creeper and comment them out
  6.     //// Creeper
  7.     // const creeper = new Creeper();
  8.     // creeper.position.set( 0, 0, -15 );
  9.     // // scene.add( creeper );
  10.     // creeper.toggleAnimate();
  11.  
  12.     // Find this line and comment it out
  13.     //plane.position.set( 0, -7, 0 );
  14.  
  15.     // Find this codes for camera, comment them out and add the following line
  16.     //// Add camera
  17.     //const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
  18.     //camera.position.set( 30, 30, 30 );
  19.     //camera.lookAt( scene.position );
  20.     const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
  21.  
  22.     // Find this codes for PhysicsEngine, comment them out and add the following
  23.     // const physicsEngine = new PhysicsEngine();
  24.     // physicsEngine.initialize();
  25.     // physicsEngine.mock(scene, 30);
  26.     const physicsEngine = new PhysicsEngine( scene, camera );
  27.     physicsEngine.initialize();
  28.     physicsEngine.mock( 10 );
  29.  
  30.     // Find this line and comment it out
  31.     //let groundCM = new CANNON.Material()
  32.     // Find groundBody and change its material to physicsEngine.physicsMaterial like the below one
  33.     groundBody = new CANNON.Body({
  34.       mass: 0,
  35.       shape: groundShape,
  36.       material: physicsEngine.physicsMaterial
  37.     });
  38.     // setFromAxisAngle 旋轉 x 軸 -90 度
  39.     groundBody.quaternion.setFromAxisAngle( new CANNON.Vec3( 1, 0, 0 ), -Math.PI / 2 );
  40.     //groundBody.position.set( 0, -7, 0 );
  41.     physicsEngine.world.add( groundBody );
  42.  
  43.     // Here we start adding creeper back
  44.     // Creeper
  45.     const world = physicsEngine.world;
  46.     let creeper = new Creeper( 0.19, 10, scene, world );
  47.  
  48.     // Find the render function
  49.     function render() {
  50.       // ... other code snippet
  51.      
  52.       // then find `navTool.update` and replace it with the below one
  53.       navTool.update( scene, () => {
  54.         physicsEngine.update(navTool);
  55.         creeper.update();
  56.       });
  57.  
  58.       // ... other code snippet
  59.       // Find this line and comment it out
  60.       //creeper.animate();
  61.     }
  62.  
  63.     // ... other code snippet
  64.  
  65.  
  66.   // Find this event callback and replace it with the following
  67.   resetBtn.addEventListener( 'click', function() {
  68.     creeper.dispose();
  69.  
  70.     creeper = new Creeper( 0.19, 10, scene, world );
  71.   });
  72.  
  73. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement