minor CharacterView refactoring

This commit is contained in:
azykov@mail.ru 2026-06-03 21:40:48 +03:00
parent 63bd5e3715
commit 9aacd70abc
No known key found for this signature in database
2 changed files with 11 additions and 15 deletions

View File

@ -8,8 +8,9 @@ export const CharacterView = observer(function ({ character }: { character: Char
return ( return (
<SyncRigidBody <SyncRigidBody
colliders="hull" colliders="cuboid"
restitution={2} position={[pos[0] + 0.5, pos[1] + 0.5, pos[2] + 0.5]}
rotation={character.transform.look}
onSync={(data) => { onSync={(data) => {
state.game?.setCharacterTransform( state.game?.setCharacterTransform(
{ {
@ -21,14 +22,12 @@ export const CharacterView = observer(function ({ character }: { character: Char
); );
}} }}
> >
<group <group>
position={[pos[0] + 0.5, pos[1] + 0.5, pos[2] + 0.5]}
rotation={character.transform.look}
>
<mesh position={[0, 0, 0]} rotation={[-Math.PI / 2, -Math.PI / 4, 0]}> <mesh position={[0, 0, 0]} rotation={[-Math.PI / 2, -Math.PI / 4, 0]}>
<coneGeometry args={[0.55, 0.8, 4]} /> <coneGeometry args={[0.55, 0.8, 4]} />
<meshStandardMaterial color="yellow" /> <meshStandardMaterial color="yellow" />
</mesh> </mesh>
{/* <ConvexHullCollider args={[object.cache.colliderMesh[0]]} /> */}
</group> </group>
</SyncRigidBody> </SyncRigidBody>
); );

View File

@ -3,7 +3,7 @@ import { SceneView } from "./SceneView";
import { state } from "../state"; import { state } from "../state";
import { useFrame, useThree } from "@react-three/fiber"; import { useFrame, useThree } from "@react-three/fiber";
import { PointerLockControls, useKeyboardControls } from "@react-three/drei"; import { PointerLockControls, useKeyboardControls } from "@react-three/drei";
import { Suspense, useEffect, useRef } from "react"; import { Suspense, useRef } from "react";
import { Physics } from "@react-three/rapier"; import { Physics } from "@react-three/rapier";
function PlayerMovement() { function PlayerMovement() {
@ -41,16 +41,13 @@ export const GameView = observer(function () {
const game = state.game; const game = state.game;
const { camera } = useThree(); const { camera } = useThree();
useEffect(() => { useFrame((_, delta) => {
if (!game) state.game?.tick(delta);
return;
if (!game) return;
const { position, look } = game.camera; const { position, look } = game.camera;
camera.position.set(position[0], position[1], position[2]); camera.position.set(position[0], position[1], position[2]);
camera.rotation.set(look[0], look[1], look[2]); camera.rotation.set(look[0], look[1], look[2]);
}, []);
useFrame((_, delta) => {
state.game?.tick(delta);
}); });
if (!game) if (!game)
@ -59,7 +56,7 @@ export const GameView = observer(function () {
return (<> return (<>
<Suspense> <Suspense>
<PlayerMovement /> <PlayerMovement />
<Physics paused={game.isPaused}> <Physics paused={game.isPaused} debug>
<SceneView scene={game.scene} /> <SceneView scene={game.scene} />
</Physics> </Physics>
</Suspense> </Suspense>