fix:(game) fixed infinite jump glitch
parent
8138f4338f
commit
bf52a80c29
Binary file not shown.
Binary file not shown.
|
@ -22,6 +22,7 @@ import { Banana } from "./models/items/Banana_peel_mario_kart";
|
|||
import { ItemBox } from "./models/misc/Mario_kart_item_box";
|
||||
import { useStore } from "./store";
|
||||
import { Shell } from "./models/items/Mario_shell_red";
|
||||
import { Coin } from "./models/misc/Super_mario_bros_coin";
|
||||
|
||||
export const Experience = () => {
|
||||
const onCollide = (event) => {
|
||||
|
@ -36,11 +37,13 @@ export const Experience = () => {
|
|||
<Banana onCollide={onCollide} position={[-10, 1.8, -119]} />
|
||||
{/* <Shell position={[-20, 2, -119]} /> */}
|
||||
<ItemBox position={[-20, 2, -119]} />
|
||||
<Coin position={[-30, 2, -119]} />
|
||||
|
||||
<Ground position={[0, 0, 0]} />
|
||||
<Environment resolution={256} preset="lobby" />
|
||||
|
||||
|
||||
|
||||
{bananas.map((banana) => (
|
||||
<Banana
|
||||
key={banana.id}
|
||||
|
|
|
@ -90,8 +90,6 @@ export const PlayerController = () => {
|
|||
useFrame(({ pointer, clock }, delta) => {
|
||||
const time = clock.getElapsedTime();
|
||||
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.setPlaybackRate(currentSpeed / 10 + 0.1);
|
||||
jumpSound.current.setPlaybackRate(1.5);
|
||||
|
@ -219,11 +217,12 @@ export const PlayerController = () => {
|
|||
);
|
||||
|
||||
// JUMPING
|
||||
if (jumpPressed && isOnFloor.current && !jumpIsHeld.current) {
|
||||
if (jumpPressed && isOnGround && !jumpIsHeld.current) {
|
||||
jumpForce.current += 10;
|
||||
isOnFloor.current = false;
|
||||
jumpIsHeld.current = true;
|
||||
jumpSound.current.play();
|
||||
setIsOnGround(false);
|
||||
|
||||
if (jumpSound.current.isPlaying) {
|
||||
jumpSound.current.stop();
|
||||
|
@ -234,7 +233,7 @@ export const PlayerController = () => {
|
|||
if (isOnFloor.current && jumpForce.current > 0) {
|
||||
landingSound.current.play();
|
||||
}
|
||||
if (!isOnFloor.current && jumpForce.current > 0) {
|
||||
if (!isOnGround && jumpForce.current > 0 ) {
|
||||
jumpForce.current -= 1 * delta * 144;
|
||||
}
|
||||
if (!jumpPressed) {
|
||||
|
@ -462,10 +461,6 @@ export const PlayerController = () => {
|
|||
actions.useItem();
|
||||
}
|
||||
|
||||
if(item) console.log(item)
|
||||
|
||||
// console.lowg(body.current.translation())
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
@ -485,6 +480,11 @@ export const PlayerController = () => {
|
|||
mass={3}
|
||||
onCollisionEnter={({other}) => {
|
||||
isOnFloor.current = true;
|
||||
setIsOnGround(true);
|
||||
}}
|
||||
onCollisionExit={({other}) => {
|
||||
isOnFloor.current = false;
|
||||
setIsOnGround(false);
|
||||
}}
|
||||
|
||||
/>
|
||||
|
|
|
@ -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')
|
Loading…
Reference in New Issue