Skip to content

Commit 00115c9

Browse files
committed
feat: bump @react-three/rapier from 1.3.1 to 1.4.0
1 parent f90fcb4 commit 00115c9

File tree

4 files changed

+32
-51
lines changed

4 files changed

+32
-51
lines changed

example/FloatingPlatform.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {
22
CuboidCollider,
3-
RapierRigidBody,
43
RigidBody,
54
useRapier,
65
} from "@react-three/rapier";
76
import { useEffect, useRef, useMemo } from "react";
87
import * as THREE from "three";
98
import { useFrame } from "@react-three/fiber";
109
import { Text } from "@react-three/drei";
11-
import type { RayColliderToi } from "@dimforge/rapier3d-compat";
10+
import type { RayColliderHit } from "@dimforge/rapier3d-compat";
1211

1312
export default function FloatingPlatform() {
1413
// Preset
@@ -27,22 +26,22 @@ export default function FloatingPlatform() {
2726
const springDirVec = useMemo(() => new THREE.Vector3(), []);
2827
const origin = useMemo(() => new THREE.Vector3(), []);
2928
const rayCast = new rapier.Ray(origin, rayDir);
30-
let rayHit: RayColliderToi = null;
29+
let rayHit: RayColliderHit | null = null;
3130
const floatingDis = 0.8;
3231
const springK = 2.5;
3332
const dampingC = 0.15;
3433
// Platform 2
3534
const springDirVec2 = useMemo(() => new THREE.Vector3(), []);
3635
const origin2 = useMemo(() => new THREE.Vector3(), []);
3736
const rayCast2 = new rapier.Ray(origin2, rayDir);
38-
let rayHit2: RayColliderToi = null;
37+
let rayHit2: RayColliderHit | null = null;
3938
// Moving Platform
4039
const springDirVecMove = useMemo(() => new THREE.Vector3(), []);
4140
const originMove = useMemo(() => new THREE.Vector3(), []);
4241
const rayCastMove = new rapier.Ray(originMove, rayDir);
4342
const movingVel = useMemo(() => new THREE.Vector3(), []);
4443
let movingDir = 1;
45-
let rayHitMove: RayColliderToi = null;
44+
let rayHitMove: RayColliderHit | null = null;
4645

4746
useEffect(() => {
4847
// Loack platform 1 rotation
@@ -74,8 +73,8 @@ export default function FloatingPlatform() {
7473
rayCast,
7574
rayLength,
7675
false,
77-
null,
78-
null,
76+
undefined,
77+
undefined,
7978
floatingPlateRef.current,
8079
floatingPlateRef.current
8180
);
@@ -91,8 +90,8 @@ export default function FloatingPlatform() {
9190
rayCast2,
9291
rayLength,
9392
false,
94-
null,
95-
null,
93+
undefined,
94+
undefined,
9695
floatingPlateRef2.current,
9796
floatingPlateRef2.current
9897
);
@@ -108,8 +107,8 @@ export default function FloatingPlatform() {
108107
rayCastMove,
109108
rayLength,
110109
false,
111-
null,
112-
null,
110+
undefined,
111+
undefined,
113112
floatingMovingPlateRef.current,
114113
floatingMovingPlateRef.current
115114
);
@@ -138,7 +137,7 @@ export default function FloatingPlatform() {
138137
if (rayHit) {
139138
if (rayHit.collider.parent()) {
140139
const floatingForce =
141-
springK * (floatingDis - rayHit.toi) -
140+
springK * (floatingDis - rayHit.timeOfImpact) -
142141
floatingPlateRef.current.linvel().y * dampingC;
143142
floatingPlateRef.current.applyImpulse(
144143
springDirVec.set(0, floatingForce, 0),
@@ -151,7 +150,7 @@ export default function FloatingPlatform() {
151150
if (rayHit2) {
152151
if (rayHit2.collider.parent()) {
153152
const floatingForce2 =
154-
springK * (floatingDis - rayHit2.toi) -
153+
springK * (floatingDis - rayHit2.timeOfImpact) -
155154
floatingPlateRef2.current.linvel().y * dampingC;
156155
floatingPlateRef2.current.applyImpulse(
157156
springDirVec2.set(0, floatingForce2, 0),
@@ -164,7 +163,7 @@ export default function FloatingPlatform() {
164163
if (rayHitMove) {
165164
if (rayHitMove.collider.parent()) {
166165
const floatingForceMove =
167-
springK * (floatingDis - rayHitMove.toi) -
166+
springK * (floatingDis - rayHitMove.timeOfImpact) -
168167
floatingMovingPlateRef.current.linvel().y * dampingC;
169168
floatingMovingPlateRef.current.applyImpulse(
170169
springDirVecMove.set(0, floatingForceMove, 0),

package-lock.json

Lines changed: 10 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"peerDependencies": {
4949
"@react-three/drei": ">=9.0",
5050
"@react-three/fiber": ">=8.0",
51-
"@react-three/rapier": ">=1.0",
51+
"@react-three/rapier": ">=1.4.0",
5252
"react": ">=18",
5353
"react-dom": ">=18.0",
5454
"three": ">=0.153"

src/Ecctrl.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useGame } from "./stores/useGame";
1717
import { useJoystickControls } from "./stores/useJoystickControls";
1818
import type {
1919
Collider,
20-
RayColliderToi,
20+
RayColliderHit,
2121
Vector,
2222
} from "@dimforge/rapier3d-compat";
2323
import React from "react";
@@ -569,7 +569,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
569569
const characterMassForce: THREE.Vector3 = useMemo(() => new THREE.Vector3(), []);
570570
const rayOrigin: THREE.Vector3 = useMemo(() => new THREE.Vector3(), []);
571571
const rayCast = new rapier.Ray(rayOrigin, rayDir);
572-
let rayHit: RayColliderToi = null;
572+
let rayHit: RayColliderHit | null = null;
573573

574574
/**Test shape ray */
575575
// const shape = new rapier.Capsule(0.2,0.1)
@@ -585,7 +585,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
585585
const slopeRayOriginRef = useRef<THREE.Mesh>();
586586
const slopeRayorigin: THREE.Vector3 = useMemo(() => new THREE.Vector3(), []);
587587
const slopeRayCast = new rapier.Ray(slopeRayorigin, slopeRayDir);
588-
let slopeRayHit: RayColliderToi = null;
588+
let slopeRayHit: RayColliderHit | null = null;
589589

590590
/**
591591
* Point to move setup
@@ -1127,7 +1127,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
11271127
// characterRef.current
11281128
// );
11291129

1130-
if (rayHit && rayHit.toi < floatingDis + rayHitForgiveness) {
1130+
if (rayHit && rayHit.timeOfImpact < floatingDis + rayHitForgiveness) {
11311131
if (slopeRayHit && actualSlopeAngle < slopeMaxAngle) {
11321132
canJump = true;
11331133
}
@@ -1143,7 +1143,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
11431143
// Getting the standing force apply point
11441144
standingForcePoint.set(
11451145
rayOrigin.x,
1146-
rayOrigin.y - rayHit.toi,
1146+
rayOrigin.y - rayHit.timeOfImpact,
11471147
rayOrigin.z
11481148
);
11491149
const rayHitObjectBodyType = rayHit.collider.parent().bodyType();
@@ -1260,12 +1260,12 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
12601260
actualSlopeAngle = actualSlopeNormalVec?.angleTo(floorNormal);
12611261
}
12621262
}
1263-
if (slopeRayHit && rayHit && slopeRayHit.toi < floatingDis + 0.5) {
1263+
if (slopeRayHit && rayHit && slopeRayHit.timeOfImpact < floatingDis + 0.5) {
12641264
if (canJump) {
12651265
// Round the slope angle to 2 decimal places
12661266
slopeAngle = Number(
12671267
Math.atan(
1268-
(rayHit.toi - slopeRayHit.toi) / slopeRayOriginOffest
1268+
(rayHit.timeOfImpact - slopeRayHit.timeOfImpact) / slopeRayOriginOffest
12691269
).toFixed(2)
12701270
);
12711271
} else {
@@ -1281,7 +1281,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
12811281
if (rayHit != null) {
12821282
if (canJump && rayHit.collider.parent()) {
12831283
floatingForce =
1284-
springK * (floatingDis - rayHit.toi) -
1284+
springK * (floatingDis - rayHit.timeOfImpact) -
12851285
characterRef.current.linvel().y * dampingC;
12861286
characterRef.current.applyImpulse(
12871287
springDirVec.set(0, floatingForce, 0),

0 commit comments

Comments
 (0)