Advertisement
yskang

threejs-minecraft-36

Apr 26th, 2020 (edited)
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Crepper
  2. // ... other code snippet
  3. creeper.position.set( 0, 0, -15 );
  4. // ... other code snippet
  5.  
  6. // Add Camera
  7. // ... other code snippet
  8. // Comment out these two lines
  9. //camera.position.set( 30, 30, 30 );
  10. //camera.lookAt( scene.position );
  11.  
  12. // Add PhysicsEngine
  13. const physicsEngine = new PhysicsEngine();
  14. physicsEngine.initialize();
  15. physicsEngine.mock( scene, 30 );
  16.  
  17. let groundShape = new CANNON.Plane();
  18. let groundCM = new CANNON.Material();
  19. const groundBody = new CANNON.Body({
  20.   mass: 0,
  21.   shape: groundShape,
  22.   material: groundCM
  23. });
  24. // setFromAxisAngle 旋轉 x θ»Έ -90 εΊ¦
  25. groundBody.quaternion.setFromAxisAngle( new CANNON.Vec3( 1, 0, 0 ), -Math.PI / 2 );
  26. groundBody.position.set( 0, -7, 0 );
  27. physicsEngine.world.add( groundBody );
  28.  
  29. // Add navigation tool
  30. // Common out the original one and add this line like following
  31. //const navTool = new NavigationTool(camera);
  32. const navTool = new NavigationTool( camera, physicsEngine.sphereBody );
  33.  
  34. // ... other code snippet
  35.  
  36. // Find this function and then ...
  37. function render() {
  38.     // ... other code snippet
  39.     // Common out the original one and add this line like following
  40.     //navTool.update(scene);
  41.     navTool.update( scene, () => {
  42.         physicsEngine.update( navTool );
  43.     });
  44. }
  45.  
  46. // Common out this event handler
  47. // renderer.domElement.addEventListener('dblclick', function (event) {
  48. //   const raycaster = new THREE.Raycaster();
  49. //   const mouse = new THREE.Vector2();
  50. //
  51. //   mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
  52. //   mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
  53. //
  54. //   raycaster.setFromCamera(mouse.clone(), camera);
  55. //
  56. //   const intersects = raycaster.intersectObjects(creeper.children);
  57. //
  58. //   console.log(intersects);
  59. //
  60. //   const result = intersects[0];
  61. //
  62. //   if (!result) return;
  63. //
  64. //   console.log(result);
  65. //
  66. //   const hitPoint = result.point;
  67. //   const backVec = hitPoint.clone().add(raycaster.ray.direction.clone().setLength(10000));
  68. //   const backVecH = backVec.projectOnPlane(new THREE.Vector3(0, 1, 0));
  69. //   backVecH.normalize();
  70. //
  71. //   const backwardVec = backVecH.multiplyScalar(5);
  72. //   const newPos = creeper.position.clone().add(backwardVec);
  73. //   creeper.position.set(newPos.x, newPos.y, newPos.z);
  74. //
  75. //   creeper.trigger();
  76. // });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement