Browse Source

Merge pull request #22877 from Uueuuuuu/dev

Teleport Player if Out of Bounds in games_fps
Mr.doob 3 years ago
parent
commit
e26fd3bca9
1 changed files with 14 additions and 1 deletions
  1. 14 1
      examples/games_fps.html

+ 14 - 1
examples/games_fps.html

@@ -385,7 +385,7 @@
 
 
 					if ( keyStates[ 'Space' ] ) {
 					if ( keyStates[ 'Space' ] ) {
 
 
-						playerVelocity.y = 10;
+						playerVelocity.y = 15;
 
 
 					}
 					}
 
 
@@ -422,6 +422,17 @@
 
 
 			} );
 			} );
 
 
+			function teleportPlayerIfOob(){
+				if (camera.position.y <= -25){
+					playerCollider.start.set( 0, 0.35, 0 );
+					playerCollider.end.set( 0, 1, 0 );
+					playerCollider.radius =  0.35;
+					camera.position.copy( playerCollider.end );
+					camera.rotation.set( 0, 0, 0 );
+				}
+			}
+
+
 			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 +448,8 @@
 
 
 					updateSpheres( deltaTime );
 					updateSpheres( deltaTime );
 
 
+					teleportPlayerIfOob();
+
 				}
 				}
 
 
 				renderer.render( scene, camera );
 				renderer.render( scene, camera );