1
1
import {
2
2
CuboidCollider ,
3
- RapierRigidBody ,
4
3
RigidBody ,
5
4
useRapier ,
6
5
} from "@react-three/rapier" ;
7
6
import { useEffect , useRef , useMemo } from "react" ;
8
7
import * as THREE from "three" ;
9
8
import { useFrame } from "@react-three/fiber" ;
10
9
import { Text } from "@react-three/drei" ;
11
- import type { RayColliderToi } from "@dimforge/rapier3d-compat" ;
10
+ import type { RayColliderHit } from "@dimforge/rapier3d-compat" ;
12
11
13
12
export default function FloatingPlatform ( ) {
14
13
// Preset
@@ -27,22 +26,22 @@ export default function FloatingPlatform() {
27
26
const springDirVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
28
27
const origin = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
29
28
const rayCast = new rapier . Ray ( origin , rayDir ) ;
30
- let rayHit : RayColliderToi = null ;
29
+ let rayHit : RayColliderHit | null = null ;
31
30
const floatingDis = 0.8 ;
32
31
const springK = 2.5 ;
33
32
const dampingC = 0.15 ;
34
33
// Platform 2
35
34
const springDirVec2 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
36
35
const origin2 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
37
36
const rayCast2 = new rapier . Ray ( origin2 , rayDir ) ;
38
- let rayHit2 : RayColliderToi = null ;
37
+ let rayHit2 : RayColliderHit | null = null ;
39
38
// Moving Platform
40
39
const springDirVecMove = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
41
40
const originMove = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
42
41
const rayCastMove = new rapier . Ray ( originMove , rayDir ) ;
43
42
const movingVel = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
44
43
let movingDir = 1 ;
45
- let rayHitMove : RayColliderToi = null ;
44
+ let rayHitMove : RayColliderHit | null = null ;
46
45
47
46
useEffect ( ( ) => {
48
47
// Loack platform 1 rotation
@@ -74,8 +73,8 @@ export default function FloatingPlatform() {
74
73
rayCast ,
75
74
rayLength ,
76
75
false ,
77
- null ,
78
- null ,
76
+ undefined ,
77
+ undefined ,
79
78
floatingPlateRef . current ,
80
79
floatingPlateRef . current
81
80
) ;
@@ -91,8 +90,8 @@ export default function FloatingPlatform() {
91
90
rayCast2 ,
92
91
rayLength ,
93
92
false ,
94
- null ,
95
- null ,
93
+ undefined ,
94
+ undefined ,
96
95
floatingPlateRef2 . current ,
97
96
floatingPlateRef2 . current
98
97
) ;
@@ -108,8 +107,8 @@ export default function FloatingPlatform() {
108
107
rayCastMove ,
109
108
rayLength ,
110
109
false ,
111
- null ,
112
- null ,
110
+ undefined ,
111
+ undefined ,
113
112
floatingMovingPlateRef . current ,
114
113
floatingMovingPlateRef . current
115
114
) ;
@@ -138,7 +137,7 @@ export default function FloatingPlatform() {
138
137
if ( rayHit ) {
139
138
if ( rayHit . collider . parent ( ) ) {
140
139
const floatingForce =
141
- springK * ( floatingDis - rayHit . toi ) -
140
+ springK * ( floatingDis - rayHit . timeOfImpact ) -
142
141
floatingPlateRef . current . linvel ( ) . y * dampingC ;
143
142
floatingPlateRef . current . applyImpulse (
144
143
springDirVec . set ( 0 , floatingForce , 0 ) ,
@@ -151,7 +150,7 @@ export default function FloatingPlatform() {
151
150
if ( rayHit2 ) {
152
151
if ( rayHit2 . collider . parent ( ) ) {
153
152
const floatingForce2 =
154
- springK * ( floatingDis - rayHit2 . toi ) -
153
+ springK * ( floatingDis - rayHit2 . timeOfImpact ) -
155
154
floatingPlateRef2 . current . linvel ( ) . y * dampingC ;
156
155
floatingPlateRef2 . current . applyImpulse (
157
156
springDirVec2 . set ( 0 , floatingForce2 , 0 ) ,
@@ -164,7 +163,7 @@ export default function FloatingPlatform() {
164
163
if ( rayHitMove ) {
165
164
if ( rayHitMove . collider . parent ( ) ) {
166
165
const floatingForceMove =
167
- springK * ( floatingDis - rayHitMove . toi ) -
166
+ springK * ( floatingDis - rayHitMove . timeOfImpact ) -
168
167
floatingMovingPlateRef . current . linvel ( ) . y * dampingC ;
169
168
floatingMovingPlateRef . current . applyImpulse (
170
169
springDirVecMove . set ( 0 , floatingForceMove , 0 ) ,
0 commit comments