fix:(game) fixed bananas not removing themselves after intersection
parent
bf52a80c29
commit
cff143c925
|
@ -48,7 +48,8 @@ export const Experience = () => {
|
|||
<Banana
|
||||
key={banana.id}
|
||||
position={banana.position}
|
||||
|
||||
banana={banana}
|
||||
id={banana.id}
|
||||
// rotation={banana.rotation}
|
||||
/>
|
||||
))}
|
||||
|
|
|
@ -422,7 +422,7 @@ export const PlayerController = () => {
|
|||
// Calculate the position for the new banana
|
||||
const bananaPosition = kartPosition.sub(scaledBackwardDirection);
|
||||
const newBanana = {
|
||||
id: Math.random() + "-" + new Date(),
|
||||
id: Math.random() + "-" + +new Date(),
|
||||
position: bananaPosition,
|
||||
player: true,
|
||||
};
|
||||
|
@ -445,7 +445,7 @@ export const PlayerController = () => {
|
|||
// Calculate the position for the new banana
|
||||
const shellPosition = kartPosition.sub(scaledBackwardDirection);
|
||||
const newShell = {
|
||||
id: Math.random() + "-" + new Date(),
|
||||
id: Math.random() + "-" + +new Date(),
|
||||
position: shellPosition,
|
||||
player: true,
|
||||
rotation: kartRotation
|
||||
|
|
|
@ -14,13 +14,16 @@ import { BallCollider, RigidBody } from '@react-three/rapier'
|
|||
import { useFrame } from '@react-three/fiber';
|
||||
import { useStore } from '../../store';
|
||||
|
||||
export function Banana({onCollide, ...props}) {
|
||||
export function Banana({onCollide, id, ...props}) {
|
||||
const { nodes, materials } = useGLTF('./models/items/banana_peel_mario_kart-transformed.glb');
|
||||
const rigidBody = useRef();
|
||||
const ref = useRef();
|
||||
const [scale, setScale] = React.useState(0.002);
|
||||
|
||||
|
||||
const {actions} = useStore();
|
||||
|
||||
console.log('banana', id);
|
||||
return (
|
||||
<>
|
||||
<RigidBody
|
||||
|
@ -28,16 +31,9 @@ export function Banana({onCollide, ...props}) {
|
|||
type='fixed'
|
||||
position={props.position}
|
||||
sensor
|
||||
onIntersectionEnter={(event) => {
|
||||
|
||||
if(scale === 0.002) {
|
||||
onIntersectionEnter={() => {
|
||||
actions.setShouldSlowDown(true);
|
||||
console.log(ref.current, rigidBody.current);
|
||||
ref.current.visible = false;
|
||||
setScale(0);
|
||||
rigidBody.setEnable(false);
|
||||
}
|
||||
|
||||
actions.removeBananaById(id);
|
||||
}}
|
||||
colliders={false}
|
||||
name='banana'
|
||||
|
|
|
@ -75,12 +75,17 @@ export const useStore = create((set, get) => ({
|
|||
},
|
||||
removeBanana: (banana) => {
|
||||
set((state) => ({
|
||||
bananas: state.bananas.filter((b) => b.id !== banana.id),
|
||||
bananas: state.bananas.filter((id) => id !== banana.id),
|
||||
}));
|
||||
},
|
||||
getBananas: () => {
|
||||
return get().bananas;
|
||||
},
|
||||
removeBananaById: (id) => {
|
||||
set((state) => ({
|
||||
bananas: state.bananas.filter((b) => b.id !== id),
|
||||
}));
|
||||
},
|
||||
setItem:() => {
|
||||
set((state) => ({
|
||||
item: state.items[Math.floor(Math.random() * state.items.length)],
|
||||
|
|
Loading…
Reference in New Issue