feat(VFX): Added skidmarks
parent
7665cd70fa
commit
c93290cd6d
|
@ -88,9 +88,16 @@ export const PlayerControllerGamepad = ({
|
||||||
const slowDownDuration = useRef(1500);
|
const slowDownDuration = useRef(1500);
|
||||||
const { buttonA, buttonB, RB, LB, joystick, select, start } = useGamepad();
|
const { buttonA, buttonB, RB, LB, joystick, select, start } = useGamepad();
|
||||||
|
|
||||||
|
const skidRotation = useRef(0);
|
||||||
|
|
||||||
|
const rightWheel = useRef();
|
||||||
|
const leftWheel = useRef();
|
||||||
|
const isDrifting = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(kart.current) {
|
if(leftWheel.current && rightWheel.current && body.current) {
|
||||||
actions.setBody(body.current);
|
actions.setLeftWheel(leftWheel.current);
|
||||||
|
actions.setRightWheel(rightWheel.current);
|
||||||
|
actions.setIsDrifting(isDrifting.current);
|
||||||
}
|
}
|
||||||
}, [body.current]);
|
}, [body.current]);
|
||||||
|
|
||||||
|
@ -100,6 +107,7 @@ export const PlayerControllerGamepad = ({
|
||||||
if (player.id !== id) return;
|
if (player.id !== id) return;
|
||||||
const time = clock.getElapsedTime();
|
const time = clock.getElapsedTime();
|
||||||
if (!body.current && !mario.current) return;
|
if (!body.current && !mario.current) return;
|
||||||
|
isDrifting.current = driftLeft.current || driftRight.current;
|
||||||
engineSound.current.setVolume(currentSpeed / 300 + 0.2);
|
engineSound.current.setVolume(currentSpeed / 300 + 0.2);
|
||||||
engineSound.current.setPlaybackRate(currentSpeed / 10 + 0.1);
|
engineSound.current.setPlaybackRate(currentSpeed / 10 + 0.1);
|
||||||
jumpSound.current.setPlaybackRate(1.5);
|
jumpSound.current.setPlaybackRate(1.5);
|
||||||
|
@ -122,8 +130,6 @@ export const PlayerControllerGamepad = ({
|
||||||
actions.setGameStarted(false);
|
actions.setGameStarted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mouse steering
|
|
||||||
|
|
||||||
if (!driftLeft.current && !driftRight.current) {
|
if (!driftLeft.current && !driftRight.current) {
|
||||||
steeringAngle = currentSteeringSpeed * -joystick[0];
|
steeringAngle = currentSteeringSpeed * -joystick[0];
|
||||||
targetXPosition = -camMaxOffset * -joystick[0];
|
targetXPosition = -camMaxOffset * -joystick[0];
|
||||||
|
@ -475,6 +481,8 @@ export const PlayerControllerGamepad = ({
|
||||||
player.setState("turboColor", turboColor);
|
player.setState("turboColor", turboColor);
|
||||||
player.setState("scale", scale);
|
player.setState("scale", scale);
|
||||||
player.setState("bananas", bananas);
|
player.setState("bananas", bananas);
|
||||||
|
|
||||||
|
skidRotation.current = kartRotation + mario.current.rotation.y;
|
||||||
});
|
});
|
||||||
|
|
||||||
return player.id === id ? (
|
return player.id === id ? (
|
||||||
|
@ -513,7 +521,7 @@ export const PlayerControllerGamepad = ({
|
||||||
/>
|
/>
|
||||||
<CoinParticles coins={coins} />
|
<CoinParticles coins={coins} />
|
||||||
<ItemParticles item={item} />
|
<ItemParticles item={item} />
|
||||||
<mesh position={[0.6, 0.05, 0.5]} scale={scale}>
|
<mesh position={[0.6, 0.05, 0.5]} scale={scale} ref={rightWheel}>
|
||||||
<sphereGeometry args={[0.05, 16, 16]} />
|
<sphereGeometry args={[0.05, 16, 16]} />
|
||||||
<meshStandardMaterial
|
<meshStandardMaterial
|
||||||
emissive={turboColor}
|
emissive={turboColor}
|
||||||
|
@ -542,6 +550,8 @@ export const PlayerControllerGamepad = ({
|
||||||
opacity={0.4}
|
opacity={0.4}
|
||||||
/>
|
/>
|
||||||
</mesh>
|
</mesh>
|
||||||
|
<mesh position={[-0.46, 0.05, 0.3]} ref={leftWheel}>
|
||||||
|
</mesh>
|
||||||
<mesh position={[-0.6, 0.05, 0.5]} scale={scale * 10}>
|
<mesh position={[-0.6, 0.05, 0.5]} scale={scale * 10}>
|
||||||
<sphereGeometry args={[0.05, 16, 16]} />
|
<sphereGeometry args={[0.05, 16, 16]} />
|
||||||
<FakeGlowMaterial
|
<FakeGlowMaterial
|
||||||
|
@ -551,6 +561,8 @@ export const PlayerControllerGamepad = ({
|
||||||
glowSharpness={1}
|
glowSharpness={1}
|
||||||
/>
|
/>
|
||||||
</mesh>
|
</mesh>
|
||||||
|
<mesh position={[0.46, 0.05, 0.3]} ref={rightWheel}>
|
||||||
|
</mesh>
|
||||||
{/* <FlameParticles isBoosting={isBoosting} /> */}
|
{/* <FlameParticles isBoosting={isBoosting} /> */}
|
||||||
<DriftParticlesLeft turboColor={turboColor} scale={scale} />
|
<DriftParticlesLeft turboColor={turboColor} scale={scale} />
|
||||||
<DriftParticlesRight turboColor={turboColor} scale={scale} />
|
<DriftParticlesRight turboColor={turboColor} scale={scale} />
|
||||||
|
|
|
@ -14,13 +14,17 @@ const v = new Vector3()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function Skid({ count = 500, opacity = 1, size = 2 }) {
|
export function Skid({ count = 500, opacity = 0.5, size = 0.3 }) {
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const { body } = useStore();
|
const { leftWheel, rightWheel } = useStore();
|
||||||
let index = 0
|
let index = 0
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
if (body && ref.current) {
|
const isDrifting = useStore.getState()
|
||||||
setItemAt(ref.current, e, body, index++)
|
console.log(isDrifting)
|
||||||
|
if (leftWheel && rightWheel && ref.current && isDrifting) {
|
||||||
|
setItemAt(ref.current, leftWheel.rotation, leftWheel, index++);
|
||||||
|
setItemAt(ref.current, rightWheel.rotation, rightWheel, index++);
|
||||||
|
|
||||||
if (index === count) index = 0
|
if (index === count) index = 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -35,15 +39,15 @@ export function Skid({ count = 500, opacity = 1, size = 2 }) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<instancedMesh ref={ref} args={[undefined, undefined, count]}>
|
<instancedMesh frustumCulled={false} ref={ref} args={[undefined, undefined, count]}>
|
||||||
<planeGeometry args={[size, size * 2]} />
|
<planeGeometry args={[size, size]} />
|
||||||
<meshBasicMaterial color="black" side={DoubleSide} />
|
<meshBasicMaterial color="black" side={DoubleSide} transparent opacity={opacity} />
|
||||||
</instancedMesh>
|
</instancedMesh>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setItemAt(instances, rotation, body, index) {
|
function setItemAt(instances, rotation, body, index) {
|
||||||
o.position.copy(vec3(body.translation()))
|
o.position.copy(body.getWorldPosition(v));
|
||||||
o.rotation.copy(rotation)
|
o.rotation.copy(rotation)
|
||||||
o.scale.setScalar(1)
|
o.scale.setScalar(1)
|
||||||
o.updateMatrix()
|
o.updateMatrix()
|
||||||
|
|
|
@ -17,8 +17,9 @@ export const useStore = create((set, get) => ({
|
||||||
controls: "gamepad",
|
controls: "gamepad",
|
||||||
particles1: [],
|
particles1: [],
|
||||||
particles2: [],
|
particles2: [],
|
||||||
bodyPosition: [0, 0, 0],
|
leftWheel: null,
|
||||||
bodyRotation: [0, 0, 0],
|
rightWheel: null,
|
||||||
|
bodyRotation: null,
|
||||||
pastPositions: [],
|
pastPositions: [],
|
||||||
shouldSlowdown: false,
|
shouldSlowdown: false,
|
||||||
bananas: [],
|
bananas: [],
|
||||||
|
@ -34,6 +35,7 @@ export const useStore = create((set, get) => ({
|
||||||
driftButton: false,
|
driftButton: false,
|
||||||
itemButton: false,
|
itemButton: false,
|
||||||
menuButton: false,
|
menuButton: false,
|
||||||
|
isDrifting: false,
|
||||||
addPastPosition: (position) => {
|
addPastPosition: (position) => {
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
pastPositions: [position, ...state.pastPositions.slice(0, 499)],
|
pastPositions: [position, ...state.pastPositions.slice(0, 499)],
|
||||||
|
@ -64,7 +66,7 @@ export const useStore = create((set, get) => ({
|
||||||
set({ bodyPosition: position });
|
set({ bodyPosition: position });
|
||||||
},
|
},
|
||||||
setBodyRotation: (rotation) => {
|
setBodyRotation: (rotation) => {
|
||||||
set({ bodyRotation: rotation });
|
set({ rotation });
|
||||||
},
|
},
|
||||||
getBodyPosition: () => {
|
getBodyPosition: () => {
|
||||||
return get().bodyPosition;
|
return get().bodyPosition;
|
||||||
|
@ -168,6 +170,18 @@ export const useStore = create((set, get) => ({
|
||||||
setBody: (body) => {
|
setBody: (body) => {
|
||||||
set({ body });
|
set({ body });
|
||||||
},
|
},
|
||||||
|
setLeftWheel: (leftWheel) => {
|
||||||
|
set({ leftWheel });
|
||||||
|
},
|
||||||
|
setRightWheel: (rightWheel) => {
|
||||||
|
set({ rightWheel });
|
||||||
|
},
|
||||||
|
setIsDrifting: (isDrifting) => {
|
||||||
|
set({ isDrifting });
|
||||||
|
},
|
||||||
|
getIsDrifting: () => {
|
||||||
|
return get().isDrifting;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue