@@ -56,6 +56,7 @@ export default function HUD(props: HUDProps) {
56
56
const [ thisEuler ] = useState ( new Euler ( 0 , 0 , 0 , "YXZ" ) ) ;
57
57
const [ dummy1 ] = useState ( new Quaternion ( ) ) ;
58
58
const [ dummy2 ] = useState ( new Quaternion ( ) ) ;
59
+ const [ hud ] = useState ( new Vector2 ( ) ) ;
59
60
60
61
const [ spring , set ] = useSpring ( ( ) => ( {
61
62
offset : [ 0 , 0 ] ,
@@ -77,9 +78,8 @@ export default function HUD(props: HUDProps) {
77
78
lerpedPos . lerp ( targetPos , alpha ) ;
78
79
79
80
// calculate x position based on camera and screen width
80
- const hud = getHudPos ( lerpedPos , camera as PerspectiveCamera , distance ) ;
81
- const { x, y } = hud ;
82
- group . current . position . set ( x , y , - distance ) ;
81
+ getHudPos ( lerpedPos , camera as PerspectiveCamera , distance , hud ) ;
82
+ group . current . position . set ( hud . x , hud . y , - distance ) ;
83
83
84
84
// calculate rotation velocities about the respective ROTATION axis (not screen space)
85
85
dummy1 . copy ( lastQuat ) ;
@@ -125,10 +125,9 @@ export default function HUD(props: HUDProps) {
125
125
// bob a bit based on player velocity
126
126
const vel_len = velocity . get ( ) . length ( ) > 1 ? 1 : 0 ;
127
127
const strength = bobStrength || Math . max ( lerpedPos . length ( ) , 0.05 ) ;
128
- x_axis_vel +=
129
- Math . sin ( clock . getElapsedTime ( ) * 15 ) * vel_len * 0.2 * strength ;
128
+ x_axis_vel += Math . sin ( clock . elapsedTime * 15 ) * vel_len * 0.2 * strength ;
130
129
y_axis_vel +=
131
- Math . cos ( clock . getElapsedTime ( ) * 20 + 12 ) * vel_len * 0.1 * strength ;
130
+ Math . cos ( clock . elapsedTime * 20 + 12 ) * vel_len * 0.1 * strength ;
132
131
133
132
// set spring targets based on velocities
134
133
const scale_ang = 0.1 ;
0 commit comments