updated the collision for jumps and terrain

This commit is contained in:
phenom committed 2026-08-16 18:07:34 -04:00
1 parent c00f3211ea
commit e39aebf3a1
5 files changed
+138 -18

No files matched your search

+10 -14
View File
@@ -41,12 +41,12 @@ import {
import {
PLAYER_GROUND_PROBE_DISTANCE,
PLAYER_JUMP_VELOCITY,
PLAYER_LANDING_PRESENTATION_MS,
bufferPlayerJump,
cancelBufferedPlayerJump,
characterVerticalMotion,
createCharacterVerticalPresentationTiming,
createPlayerJumpTiming,
isWalkableGroundHit,
updateCharacterVerticalPresentation,
updatePlayerJumpTiming,
type CharacterVerticalMotion,
} from "../game/playerJump";
@@ -123,16 +123,14 @@ function PlayerController({
[rapier],
);
const jumpTimingRef = useRef(createPlayerJumpTiming());
const wasGroundedRef = useRef(true);
const landingUntilRef = useRef(Number.NEGATIVE_INFINITY);
const verticalPresentationTimingRef = useRef(createCharacterVerticalPresentationTiming());
useEffect(() => {
if (bodyRef.current) placeAtActiveSpawn(bodyRef.current, orbitRef.current);
lastReported.current = [...spawn.footPosition];
clearJumpRequest();
jumpTimingRef.current = createPlayerJumpTiming(performance.now());
wasGroundedRef.current = true;
landingUntilRef.current = Number.NEGATIVE_INFINITY;
verticalPresentationTimingRef.current = createCharacterVerticalPresentationTiming();
verticalMotionRef.current = "grounded";
}, [bodyRef, orbitRef, resetRevision, spawn, verticalMotionRef]);
@@ -189,11 +187,12 @@ function PlayerController({
if (gameplayBlocked) {
cancelBufferedPlayerJump(jumpTimingRef.current);
movingRef.current = false;
verticalMotionRef.current = characterVerticalMotion(
verticalMotionRef.current = updateCharacterVerticalPresentation(
verticalPresentationTimingRef.current,
grounded,
velocity.y,
nowMs,
landingUntilRef.current,
false,
);
body.setLinvel({ x: 0, y: velocity.y, z: 0 }, true);
return;
@@ -208,15 +207,12 @@ function PlayerController({
);
const verticalVelocity = shouldJump ? PLAYER_JUMP_VELOCITY : velocity.y;
if (shouldJump) grounded = false;
if (grounded && !wasGroundedRef.current) {
landingUntilRef.current = nowMs + PLAYER_LANDING_PRESENTATION_MS;
}
wasGroundedRef.current = grounded;
verticalMotionRef.current = characterVerticalMotion(
verticalMotionRef.current = updateCharacterVerticalPresentation(
verticalPresentationTimingRef.current,
grounded,
verticalVelocity,
nowMs,
landingUntilRef.current,
shouldJump,
);
const [worldX, worldZ] = cameraRelativeMovement(