Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huddles rotation and movement added #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 29 additions & 38 deletions src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,37 @@ const Dash = () => {
);
};

// const Huddle = ({
// args = [2, 0.3, 0.5],
// color,
// speed = 0.1,
// long = false,
// y = 2,
// right = false,
// ...props
// }) => {
// const { viewport } = useThree();
// const { width } = viewport;
// const [ref, api] = useBox(() => ({ args, ...props }));
// let initial = right ? width : -width;
// let r = Math.random();
// let rot = 0.2 * speed;
// let x = initial;
// let z = 0;
// useFrame((state, delta) => {
// //api.rotation.set(0, 0, r * Math.PI + (right ? (z += rot) : (z -= rot)))
// api.position.set((x = right ? x - speed : x + speed), y, 0);
// if (right ? x + 2 < -width / 2 : x - 2 > width / 2) x = initial;
// });
// return (
// <mesh ref={ref}>
// <boxBufferGeometry attach="geometry" args={args} />
// <meshStandardMaterial attach="material" color={color} />
// </mesh>
// );
// };
const Huddle = ({
args = [2, 0.3, 0.5],
color,
speed = 0.1,
long = false,
y = 2,
right = false,
...props
}) => {
const { viewport } = useThree();
const { width } = viewport;
const [ref, api] = useBox(() => ({ args, ...props }));
let initial = right ? width : -width;
let r = Math.random();
let rot = 0.2 * speed;
let x = initial;
let z = 0;
useFrame((state, delta) => {
//api.rotation.set(0, 0, r * Math.PI + (right ? (z += rot) : (z -= rot)))
api.position.set((x = right ? x - speed : x + speed), y, 0);
if (right ? x + 2 < -width / 2 : x - 2 > width / 2) x = initial;
});
return (
<mesh ref={ref}>
<boxBufferGeometry attach="geometry" args={args} />
<meshStandardMaterial attach="material" color={color} />
</mesh>
);
};

const Huddle = ({ args = [2, 0.3, 0.5], color, ...props }) => {
const [ref, api] = useBox(() => ({ args, ...props }));

return (
<mesh ref={ref}>
<boxBufferGeometry attach="geometry" args={args} />
<meshStandardMaterial attach="material" color={color} />
</mesh>
);
};

const Game = () => {
return (
Expand Down