11import {
22 CuboidCollider ,
3- RapierRigidBody ,
43 RigidBody ,
54 useRapier ,
65} from "@react-three/rapier" ;
76import { useEffect , useRef , useMemo } from "react" ;
87import * as THREE from "three" ;
98import { useFrame } from "@react-three/fiber" ;
109import { Text } from "@react-three/drei" ;
11- import type { RayColliderToi } from "@dimforge/rapier3d-compat" ;
10+ import type { RayColliderHit } from "@dimforge/rapier3d-compat" ;
1211
1312export 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 ) ,
0 commit comments