@@ -29,7 +29,7 @@ class Player {
2929 this . lastWPressTime = 0 ;
3030 this . wWasDown = false ;
3131
32- this . physicsEnabled = false ;
32+ this . enablePhysics = true ;
3333
3434 this . camera = new THREE . PerspectiveCamera ( 75 , SETTINGS . ASPECT_RATIO , 0.1 , SETTINGS . CLIPPING_DISTANCE ) ;
3535 this . camera . rotation . order = "YXZ" ;
@@ -42,7 +42,7 @@ class Player {
4242 moveX ( delta , world ) {
4343 const newX = this . position . x + this . velocity . x * delta ;
4444
45- if ( ! isColliding ( world , newX , this . position . y , this . position . z , this . width , this . height ) && this . physicsEnabled ) {
45+ if ( ! isColliding ( world , newX , this . position . y , this . position . z , this . width , this . height ) && this . enablePhysics ) {
4646 if ( this . isCrouching && this . isGrounded && ! hasGroundBelow ( world , newX , this . position . y , this . position . z , this . width ) ) {
4747 // nothing
4848 } else {
@@ -54,7 +54,7 @@ class Player {
5454 moveY ( delta , world ) {
5555 const newY = this . position . y + this . velocity . y * delta ;
5656
57- if ( ! isColliding ( world , this . position . x , newY , this . position . z , this . width , this . height ) && this . position . y > 0 && this . physicsEnabled ) {
57+ if ( ! isColliding ( world , this . position . x , newY , this . position . z , this . width , this . height ) && this . position . y > 0 && this . enablePhysics ) {
5858 this . position . y = newY ;
5959 } else {
6060 if ( this . velocity . y < 0 ) {
@@ -68,7 +68,7 @@ class Player {
6868 moveZ ( delta , world ) {
6969 const newZ = this . position . z + this . velocity . z * delta ;
7070
71- if ( ! isColliding ( world , this . position . x , this . position . y , newZ , this . width , this . height ) && this . physicsEnabled ) {
71+ if ( ! isColliding ( world , this . position . x , this . position . y , newZ , this . width , this . height ) && this . enablePhysics ) {
7272 if ( this . isCrouching && this . isGrounded && ! hasGroundBelow ( world , this . position . x , this . position . y , newZ , this . width ) ) {
7373 // nothing
7474 } else {
@@ -131,7 +131,8 @@ class Player {
131131 }
132132
133133 applyGravity ( delta ) {
134- this . velocity . y -= this . gravity * delta ;
134+ if ( this . enablePhysics )
135+ this . velocity . y -= this . gravity * delta ;
135136 }
136137
137138 handleJump ( ) {
@@ -143,7 +144,11 @@ class Player {
143144
144145 update ( delta , world ) {
145146 INPUT_MANAGER . updateRotation ( this . rotation ) ;
146-
147+
148+ if ( this . position . y < - 5 ) {
149+ this . position = BLOCK_MANAGER . TopPositionInWorld ( - SETTINGS . SPAWN_DISTANCE , SETTINGS . SPAWN_DISTANCE , - SETTINGS . SPAWN_DISTANCE , SETTINGS . SPAWN_DISTANCE , world ) ;
150+ }
151+
147152 this . updateMovement ( delta ) ;
148153 this . handleJump ( ) ;
149154 this . applyGravity ( delta ) ;
0 commit comments