import { Controls } from "../App"; import { BallCollider, RigidBody, useRapier, vec3 } from "@react-three/rapier"; import { useKeyboardControls, PerspectiveCamera, ContactShadows, Sphere, OrbitControls, Trail, PositionalAudio, } from "@react-three/drei"; import { useFrame, useThree } from "@react-three/fiber"; import { useRef, useState, useEffect, useCallback } from "react"; import * as THREE from "three"; import { Mario } from "./models/characters/Mario_kart"; import { DriftParticlesLeft } from "./Particles/drifts/DriftParticlesLeft"; import { DriftParticlesRight } from "./Particles/drifts/DriftParticlesRight"; import { PointParticle } from "./Particles/drifts/PointParticle"; import { FlameParticles } from "./Particles/flames/FlameParticles"; import { useStore } from "./store"; import { Cylinder } from "@react-three/drei"; import FakeGlowMaterial from "./ShaderMaterials/FakeGlow/FakeGlowMaterial"; import { HitParticles } from "./Particles/hits/HitParticles"; import { CoinParticles } from "./Particles/coins/CoinParticles"; import { ItemParticles } from "./Particles/items/ItemParticles"; import { isHost } from "playroomkit"; import { Banana } from "./models/items/Banana_peel_mario_kart"; export const PlayerDummies = ( { player, userPlayer }) => { const upPressed = useKeyboardControls((state) => state[Controls.up]); const downPressed = useKeyboardControls((state) => state[Controls.down]); const leftPressed = useKeyboardControls((state) => state[Controls.left]); const rightPressed = useKeyboardControls((state) => state[Controls.right]); const jumpPressed = useKeyboardControls((state) => state[Controls.jump]); const shootPressed = useKeyboardControls((state) => state[Controls.shoot]); const resetPressed = useKeyboardControls((state) => state[Controls.reset]); const [isOnGround, setIsOnGround] = useState(false); const body = useRef(); const kart = useRef(); const cam = useRef(); const initialSpeed = 0; const maxSpeed = 30; const boostSpeed = 50; const acceleration = 0.1; const decceleration = 0.2; const damping = -0.1; const MaxSteeringSpeed = 0.01; const [currentSteeringSpeed, setCurrentSteeringSpeed] = useState(0); const [currentSpeed, setCurrentSpeed] = useState(initialSpeed); const camMaxOffset = 1; let steeringAngle = 0; const isOnFloor = useRef(false); const jumpForce = useRef(0); const jumpIsHeld = useRef(false); const driftDirection = useRef(0); const driftLeft = useRef(false); const driftRight = useRef(false); const driftForce = useRef(0); const mario = useRef(); const accumulatedDriftPower = useRef(0); const blueTurboThreshold = 10; const orangeTurboThreshold = 30; const purpleTurboThreshold = 60; const [turboColor, setTurboColor] = useState(0xffffff); const boostDuration = useRef(0); const [isBoosting, setIsBoosting] = useState(false); let targetXPosition = 0; let targetZPosition = 8; const [steeringAngleWheels, setSteeringAngleWheels] = useState(0); const engineSound = useRef(); const driftSound = useRef(); const driftTwoSound = useRef(); const driftOrangeSound = useRef(); const driftPurpleSound = useRef(); const driftBlueSound = useRef(); const jumpSound = useRef(); const landingSound = useRef(); const turboSound = useRef(); const [scale, setScale] = useState(0); const raycaster = new THREE.Raycaster(); const downDirection = new THREE.Vector3(0, -1, 0); const [shouldLaunch, setShouldLaunch] = useState(false); const effectiveBoost = useRef(0); const [networkBananas, setNetworkBananas] = useState([]); const [networkShells, setNetworkShells] = useState([]); const { actions, shouldSlowDown, item, coins, id} = useStore(); const slowDownDuration = useRef(1500); useFrame((state, delta) => { const bodyPosition = player.getState("position"); const bodyRotation = player.getState("rotation"); setIsBoosting(player.getState("isBoosting")); setShouldLaunch(player.getState("shouldLaunch")); setTurboColor(player.getState("turboColor")); setScale(player.getState("scale")); if(bodyPosition && bodyRotation && kart.current && mario.current){ kart.current.position.set(bodyPosition.x, bodyPosition.y -.5, bodyPosition.z); kart.current.rotation.set(0, bodyRotation, 0); body.current.setTranslation([bodyPosition.x, bodyPosition.y, bodyPosition.z]); } }); return player.id != id? ( <> {/* */} {/* */} ) : null; };