@@ -32,16 +32,16 @@ const getMovingDirection = (forward: boolean,
32
32
leftward : boolean ,
33
33
rightward : boolean ,
34
34
pivot : THREE . Object3D )
35
- :number | null => {
36
- if ( ! forward && ! backward && ! leftward && ! rightward ) return null ;
37
- if ( forward && leftward ) return pivot . rotation . y + Math . PI / 4 ;
38
- if ( forward && rightward ) return pivot . rotation . y - Math . PI / 4 ;
39
- if ( backward && leftward ) return pivot . rotation . y - Math . PI / 4 + Math . PI ;
40
- if ( backward && rightward ) return pivot . rotation . y + Math . PI / 4 + Math . PI ;
41
- if ( backward ) return pivot . rotation . y + Math . PI ;
42
- if ( leftward ) return pivot . rotation . y + Math . PI / 2 ;
43
- if ( rightward ) return pivot . rotation . y - Math . PI / 2 ;
44
- if ( forward ) return pivot . rotation . y ;
35
+ : number | null => {
36
+ if ( ! forward && ! backward && ! leftward && ! rightward ) return null ;
37
+ if ( forward && leftward ) return pivot . rotation . y + Math . PI / 4 ;
38
+ if ( forward && rightward ) return pivot . rotation . y - Math . PI / 4 ;
39
+ if ( backward && leftward ) return pivot . rotation . y - Math . PI / 4 + Math . PI ;
40
+ if ( backward && rightward ) return pivot . rotation . y + Math . PI / 4 + Math . PI ;
41
+ if ( backward ) return pivot . rotation . y + Math . PI ;
42
+ if ( leftward ) return pivot . rotation . y + Math . PI / 2 ;
43
+ if ( rightward ) return pivot . rotation . y - Math . PI / 2 ;
44
+ if ( forward ) return pivot . rotation . y ;
45
45
} ;
46
46
47
47
const Ecctrl = forwardRef < RapierRigidBody , EcctrlProps > ( ( {
@@ -407,6 +407,7 @@ const Ecctrl = forwardRef<RapierRigidBody, EcctrlProps>(({
407
407
// can jump setup
408
408
let canJump = false ;
409
409
let isFalling = false ;
410
+ const initialGravityScale = useMemo ( ( ) => props . gravityScale || 1 , [ ] )
410
411
411
412
// on moving object state
412
413
let isOnMovingObject = false ;
@@ -826,7 +827,7 @@ const Ecctrl = forwardRef<RapierRigidBody, EcctrlProps>(({
826
827
827
828
// Getting moving directions (IIFE)
828
829
modelEuler . y = ( ( movingDirection ) => movingDirection === null ? modelEuler . y : movingDirection )
829
- ( getMovingDirection ( forward , backward , leftward , rightward , pivot ) )
830
+ ( getMovingDirection ( forward , backward , leftward , rightward , pivot ) )
830
831
831
832
// Move character to the moving direction
832
833
if ( forward || backward || leftward || rightward )
@@ -1093,10 +1094,13 @@ const Ecctrl = forwardRef<RapierRigidBody, EcctrlProps>(({
1093
1094
* Apply larger gravity when falling
1094
1095
*/
1095
1096
if ( characterRef . current ) {
1096
- characterRef . current . setGravityScale (
1097
- currentVel . y > fallingMaxVel ? ( isFalling ? fallingGravityScale : 1 ) : 0 ,
1098
- true
1099
- )
1097
+ if ( currentVel . y < fallingMaxVel && characterRef . current . gravityScale ( ) !== 0 ) {
1098
+ characterRef . current . setGravityScale ( 0 , true )
1099
+ } else if ( isFalling && characterRef . current . gravityScale ( ) !== fallingGravityScale ) {
1100
+ characterRef . current . setGravityScale ( fallingGravityScale , true )
1101
+ } else if ( ! isFalling && characterRef . current . gravityScale ( ) !== initialGravityScale ) {
1102
+ characterRef . current . setGravityScale ( initialGravityScale , true )
1103
+ }
1100
1104
}
1101
1105
1102
1106
/**
0 commit comments