Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 committed Aug 11, 2024
1 parent f874da8 commit 0f6ac9a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/pages/yatai/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));

Expand Down Expand Up @@ -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 (
<mesh
Expand Down

0 comments on commit 0f6ac9a

Please sign in to comment.