isGrounded implementation for player
This commit is contained in:
parent
1011b7d3fc
commit
d7b484e1be
|
|
@ -30,6 +30,7 @@ export const CharacterView = observer(function ({ character, editMode }: Charact
|
|||
const rbRef = useRef<RapierRigidBody>(null);
|
||||
const [, get] = useKeyboardControls();
|
||||
const { gl } = useThree();
|
||||
const groundContacts = useRef(0);
|
||||
|
||||
const yawRef = useRef(0);
|
||||
const pitchRef = useRef(0);
|
||||
|
|
@ -93,10 +94,10 @@ export const CharacterView = observer(function ({ character, editMode }: Charact
|
|||
const vz = (fwdZ * fwdScale + fwdX * rightScale) * SPEED;
|
||||
const cur = rbRef.current.linvel();
|
||||
|
||||
const isStanding = Math.abs(cur.y) < 0.5;
|
||||
const isGrounded = groundContacts.current > 0;
|
||||
|
||||
const vy = cur.y +
|
||||
(jump && !jumpPressedRef.current && isStanding
|
||||
(jump && !jumpPressedRef.current && isGrounded
|
||||
? JUMP_SPEED
|
||||
: 0);
|
||||
jumpPressedRef.current = jump;
|
||||
|
|
@ -111,6 +112,8 @@ export const CharacterView = observer(function ({ character, editMode }: Charact
|
|||
colliders="cuboid"
|
||||
lockRotations
|
||||
position={[pos[0] + 0.5, pos[1] + 0.5, pos[2] + 0.5]}
|
||||
onCollisionEnter={() => { groundContacts.current++; }}
|
||||
onCollisionExit={() => { groundContacts.current--; }}
|
||||
onSync={(data) => {
|
||||
// state.game?.setCharacterTransform(
|
||||
// { position: data.position, look: character.transform.look },
|
||||
|
|
|
|||
Loading…
Reference in New Issue