Browse Source

Improved motion

WestLangley 6 years ago
parent
commit
1f3c444ef6
1 changed files with 8 additions and 2 deletions
  1. 8 2
      examples/misc_controls_pointerlock.html

+ 8 - 2
examples/misc_controls_pointerlock.html

@@ -299,12 +299,18 @@
 					var time = performance.now();
 					var delta = ( time - prevTime ) / 1000;
 
+					velocity.x -= velocity.x * 10.0 * delta;
+					velocity.z -= velocity.z * 10.0 * delta;
+
 					velocity.y -= 9.8 * 100.0 * delta; // 100.0 = mass
 
 					direction.z = Number( moveForward ) - Number( moveBackward );
 					direction.x = Number( moveRight ) - Number( moveLeft );
 					direction.normalize(); // this ensures consistent movements in all directions
 
+					if ( moveForward || moveBackward ) velocity.z -= direction.z * 400.0 * delta;
+					if ( moveLeft || moveRight ) velocity.x -= direction.x * 400.0 * delta;
+
 					if ( onObject === true ) {
 
 						velocity.y = Math.max( 0, velocity.y );
@@ -312,8 +318,8 @@
 
 					}
 
-					controls.moveRight( direction.x * 400.0 * delta );
-					controls.moveForward( direction.z * 400.0 * delta );
+					controls.moveRight( - velocity.x * delta );
+					controls.moveForward( - velocity.z * delta );
 
 					controls.getObject().position.y += ( velocity.y * delta ); // new behavior