From 0f6ac9a45633c3096fac6a19feca4fd382fb7474 Mon Sep 17 00:00:00 2001 From: claustra01 Date: Sun, 11 Aug 2024 15:55:11 +0900 Subject: [PATCH] refactoring --- src/pages/yatai/index.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pages/yatai/index.tsx b/src/pages/yatai/index.tsx index 0378c10..f43b213 100644 --- a/src/pages/yatai/index.tsx +++ b/src/pages/yatai/index.tsx @@ -49,10 +49,12 @@ const YataiStage = memo(() => { // 的 const Target = (props: ThreeElements["mesh"]) => { + const position = props.position as [number, number, number]; + const args: [number, number, number] = [0.7, 2, 0.7]; const [ref, api] = useBox(() => ({ mass: 1, - position: props.position as [number, number, number], + position: position, args: args, })); @@ -81,21 +83,17 @@ const YataiStage = memo(() => { useEffect(() => { if (!target) return; if ( - target.x * 2 > - (props.position as [number, number, number])[0] - args[0] / 2 && - target.x * 2 < - (props.position as [number, number, number])[0] + args[0] / 2 && - target.y * 2 > - (props.position as [number, number, number])[1] - args[1] / 2 - 2 && - target.y * 2 < - (props.position as [number, number, number])[1] + args[1] / 2 - 2 + target.x * 2 > position[0] - args[0] / 2 && + target.x * 2 < position[0] + args[0] / 2 && + target.y * 2 > position[1] - args[1] / 2 - 2 && + target.y * 2 < position[1] + args[1] / 2 - 2 ) { api.applyImpulse( [randFloat(-2, 2), 4, 8], [randFloat(-1, 1), randFloat(-1, 1), randFloat(-1, 1)], ); } - }, [target, props.position, api]); + }, [target, position, api]); return (