fix:(game) fixed infinite jump glitch

pull/3/head
Alex 2024-02-02 15:13:41 +01:00
parent 8138f4338f
commit bf52a80c29
5 changed files with 49 additions and 9 deletions

Binary file not shown.

View File

@ -22,6 +22,7 @@ import { Banana } from "./models/items/Banana_peel_mario_kart";
import { ItemBox } from "./models/misc/Mario_kart_item_box"; import { ItemBox } from "./models/misc/Mario_kart_item_box";
import { useStore } from "./store"; import { useStore } from "./store";
import { Shell } from "./models/items/Mario_shell_red"; import { Shell } from "./models/items/Mario_shell_red";
import { Coin } from "./models/misc/Super_mario_bros_coin";
export const Experience = () => { export const Experience = () => {
const onCollide = (event) => { const onCollide = (event) => {
@ -36,11 +37,13 @@ export const Experience = () => {
<Banana onCollide={onCollide} position={[-10, 1.8, -119]} /> <Banana onCollide={onCollide} position={[-10, 1.8, -119]} />
{/* <Shell position={[-20, 2, -119]} /> */} {/* <Shell position={[-20, 2, -119]} /> */}
<ItemBox position={[-20, 2, -119]} /> <ItemBox position={[-20, 2, -119]} />
<Coin position={[-30, 2, -119]} />
<Ground position={[0, 0, 0]} /> <Ground position={[0, 0, 0]} />
<Environment resolution={256} preset="lobby" /> <Environment resolution={256} preset="lobby" />
{bananas.map((banana) => ( {bananas.map((banana) => (
<Banana <Banana
key={banana.id} key={banana.id}

View File

@ -90,8 +90,6 @@ export const PlayerController = () => {
useFrame(({ pointer, clock }, delta) => { useFrame(({ pointer, clock }, delta) => {
const time = clock.getElapsedTime(); const time = clock.getElapsedTime();
if (!body.current && !mario.current) return; if (!body.current && !mario.current) return;
actions.setBodyPosition(vec3(body.current.translation()));
actions.setBodyRotation(body.current.rotation());1
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);
@ -219,11 +217,12 @@ export const PlayerController = () => {
); );
// JUMPING // JUMPING
if (jumpPressed && isOnFloor.current && !jumpIsHeld.current) { if (jumpPressed && isOnGround && !jumpIsHeld.current) {
jumpForce.current += 10; jumpForce.current += 10;
isOnFloor.current = false; isOnFloor.current = false;
jumpIsHeld.current = true; jumpIsHeld.current = true;
jumpSound.current.play(); jumpSound.current.play();
setIsOnGround(false);
if (jumpSound.current.isPlaying) { if (jumpSound.current.isPlaying) {
jumpSound.current.stop(); jumpSound.current.stop();
@ -234,7 +233,7 @@ export const PlayerController = () => {
if (isOnFloor.current && jumpForce.current > 0) { if (isOnFloor.current && jumpForce.current > 0) {
landingSound.current.play(); landingSound.current.play();
} }
if (!isOnFloor.current && jumpForce.current > 0) { if (!isOnGround && jumpForce.current > 0 ) {
jumpForce.current -= 1 * delta * 144; jumpForce.current -= 1 * delta * 144;
} }
if (!jumpPressed) { if (!jumpPressed) {
@ -462,10 +461,6 @@ export const PlayerController = () => {
actions.useItem(); actions.useItem();
} }
if(item) console.log(item)
// console.lowg(body.current.translation())
}); });
@ -485,6 +480,11 @@ export const PlayerController = () => {
mass={3} mass={3}
onCollisionEnter={({other}) => { onCollisionEnter={({other}) => {
isOnFloor.current = true; isOnFloor.current = true;
setIsOnGround(true);
}}
onCollisionExit={({other}) => {
isOnFloor.current = false;
setIsOnGround(false);
}} }}
/> />

View File

@ -0,0 +1,37 @@
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.2.16 .\super_mario_bros_coin.glb --shadows --transform
Files: .\super_mario_bros_coin.glb [48.84KB] > C:\Users\mouli\dev\r3f-vite-starter\public\models\misc\super_mario_bros_coin-transformed.glb [6.12KB] (87%)
Author: BranHelsing (https://sketchfab.com/BranHelsing)
License: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
Source: https://sketchfab.com/3d-models/super-mario-bros-coin-aa97e093847a439f9feb064134813806
Title: Super Mario Bros Coin
*/
import React, { useEffect, useRef } from 'react'
import { useGLTF, useAnimations } from '@react-three/drei'
import { useFrame } from '@react-three/fiber'
export function Coin(props) {
const group = useRef()
const { nodes, materials, animations } = useGLTF('./models/misc/super_mario_bros_coin-transformed.glb')
const { actions } = useAnimations(animations, group)
useFrame((state, delta) => {
group.current.rotation.y += 4 * delta
})
return (
<group ref={group} {...props} dispose={null}>
<group name="Sketchfab_Scene">
<group name="RootNode" scale={0.588}>
<group name="Coin" scale={0.424}>
<mesh name="Coin_CoinBlinn_0" castShadow receiveShadow geometry={nodes.Coin_CoinBlinn_0.geometry} material={materials.CoinBlinn} />
</group>
</group>
</group>
</group>
)
}
useGLTF.preload('./models/misc/super_mario_bros_coin-transformed.glb')