ソースを参照

teleport player if they have jumped oob

Joe 3 年 前
コミット
12bbdf649a
1 ファイル変更25 行追加13 行削除
  1. 25 13
      examples/games_fps.html

+ 25 - 13
examples/games_fps.html

@@ -1,16 +1,16 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="en">
 <html lang="en">
-	<head>
-		<title>three.js - misc - octree collisions</title>
-		<meta charset=utf-8 />
-		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-		<link type="text/css" rel="stylesheet" href="main.css">
-	</head>
-	<body>
-		<div id="info">Octree threejs demo - basic collisions with static triangle mesh<br />WASD to move, space to jump, use mouse to throw balls and move the camera.</div>
-		<div id="container"></div>
-
-		<script type="module">
+<head>
+	<title>three.js - misc - octree collisions</title>
+	<meta charset=utf-8 />
+	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+	<link type="text/css" rel="stylesheet" href="main.css">
+</head>
+<body>
+<div id="info">Octree threejs demo - basic collisions with static triangle mesh<br />WASD to move, space to jump, use mouse to throw balls and move the camera.</div>
+<div id="container"></div>
+
+<script type="module">
 
 
 			import * as THREE from '../build/three.module.js';
 			import * as THREE from '../build/three.module.js';
 
 
@@ -385,7 +385,7 @@
 
 
 					if ( keyStates[ 'Space' ] ) {
 					if ( keyStates[ 'Space' ] ) {
 
 
-						playerVelocity.y = 10;
+						playerVelocity.y = 15;
 
 
 					}
 					}
 
 
@@ -422,6 +422,16 @@
 
 
 			} );
 			} );
 
 
+			function teleportPlayerIfOob(){
+				if (camera.position.y <= -25){
+					playerCollider.start = new THREE.Vector3( 0, 0.35, 0 );
+					playerCollider.end = new THREE.Vector3( 0, 1, 0 );
+					playerCollider.radius =  0.35;
+					camera.position.copy( playerCollider.end );
+				}
+			}
+
+
 			function animate() {
 			function animate() {
 
 
 				const deltaTime = Math.min( 0.05, clock.getDelta() ) / STEPS_PER_FRAME;
 				const deltaTime = Math.min( 0.05, clock.getDelta() ) / STEPS_PER_FRAME;
@@ -437,6 +447,8 @@
 
 
 					updateSpheres( deltaTime );
 					updateSpheres( deltaTime );
 
 
+					teleportPlayerIfOob();
+
 				}
 				}
 
 
 				renderer.render( scene, camera );
 				renderer.render( scene, camera );
@@ -448,5 +460,5 @@
 			}
 			}
 
 
 		</script>
 		</script>
-	</body>
+</body>
 </html>
 </html>