Skip to content

Commit

Permalink
Moving camera
Browse files Browse the repository at this point in the history
  • Loading branch information
JI0PATA committed Sep 26, 2023
1 parent f5bad07 commit 74e2206
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Player.jsx
Expand Up @@ -24,7 +24,7 @@ export const Player = () => {

frontVector.set(0, 0, backward - forward);
sideVector.set(left - right, 0, 0);
direction.subVectors(frontVector, sideVector).normalize().multiplyScalar(MOVE_SPEED);
direction.subVectors(frontVector, sideVector).normalize().multiplyScalar(MOVE_SPEED).applyEuler(state.camera.rotation);

playerRef.current.wakeUp();
playerRef.current.setLinvel({ x: direction.x, y: velocity.y, z: direction.z });
Expand All @@ -35,6 +35,10 @@ export const Player = () => {
const grounded = ray && ray.collider && Math.abs(ray.toi) <= 1;

if (jump && grounded) doJump();

// moving camera
const {x, y, z} = playerRef.current.translation();
state.camera.position.set(x, y, z);
});

const doJump = () => {
Expand Down

0 comments on commit 74e2206

Please sign in to comment.