@@ -2,7 +2,8 @@ import { useVRM } from '@n3p6/react-three-vrm'
22import { useEntityManager , useYuka } from '@n3p6/react-three-yuka'
33import { useFrame } from '@react-three/fiber'
44import { useEffect } from 'react'
5- import { ArriveBehavior , GameEntity , Vehicle } from 'yuka'
5+ import { Vector3 } from 'three'
6+ import { ArriveBehavior , GameEntity , Vehicle , Vector3 as YukaVector3 } from 'yuka'
67
78const vrmUrl = import . meta. env . DEV
89 ? '/models/Hikari_SummerDress.vrm'
@@ -15,8 +16,10 @@ export const HikariYuka = () => {
1516 const vrm = useVRM ( vrmUrl )
1617 const entityManager = useEntityManager ( )
1718
18- const [ vehicleRef , vehicleEntity ] = useYuka ( Vehicle , { position : [ 0 , 0 , 0 ] } )
19- const [ playerRef , playerEntity ] = useYuka ( GameEntity , { position : [ 5 , 0 , 5 ] } )
19+ const [ vehicleRef , vehicleEntity ] = useYuka ( Vehicle , {
20+ position : [ 0 , 0 , 0 ] ,
21+ } )
22+ const [ playerRef , playerEntity ] = useYuka ( GameEntity )
2023
2124 useEffect ( ( ) => {
2225 const arriveBehavior = new ArriveBehavior ( playerEntity . position , 1.5 , 0.1 )
@@ -25,28 +28,28 @@ export const HikariYuka = () => {
2528 return ( ) => {
2629 vehicleEntity . steering . remove ( arriveBehavior )
2730 }
28- } , [ playerEntity , vehicleEntity ] )
31+ } , [ vehicleEntity , playerEntity ] )
2932
30- useFrame ( ( _ , delta ) => {
33+ useFrame ( ( state , delta ) => {
3134 // vehicle.update(delta)
3235 entityManager . update ( delta )
3336 vrm . update ( delta )
37+
38+ const position = state . camera . getWorldPosition ( new Vector3 ( ) )
39+ playerEntity . position . copy ( new YukaVector3 ( position . x , 0 , position . z ) )
3440 } )
3541
3642 return (
3743 < >
38- < primitive
39- object = { vrm . scene }
40- ref = { vehicleRef }
41- // position={[0, 0, 0]}
42- rotation = { [ 0 , Math . PI , 0 ] }
43- scale = { 1.05 }
44- />
45- < mesh ref = { playerRef } >
46- < boxGeometry args = { [ 1 , 1 , 1 ] } />
47- < meshPhysicalMaterial color = "yellow" opacity = { 0.5 } transparent />
48- < pointLight distance = { 4 } intensity = { 2 } position = { [ 0 , 0 , 0 ] } />
49- </ mesh >
44+ < group ref = { vehicleRef } >
45+ < primitive
46+ object = { vrm . scene }
47+ position = { [ 0 , 0 , 0 ] }
48+ rotation = { [ 0 , Math . PI , 0 ] }
49+ scale = { 1.05 }
50+ />
51+ </ group >
52+ < group ref = { playerRef } > </ group >
5053 </ >
5154 )
5255}
0 commit comments