@@ -64,9 +64,8 @@ class EjectableSceneObject extends SceneObject {
64
64
)
65
65
this . _ejectVelocity = this . _parentAssembly . ejectorPreferences . ejectorVelocity
66
66
67
- // Animation start at game piece
67
+ // Record start transform at the game piece center of mass
68
68
const gpBody = World . physicsSystem . getBody ( this . _gamePieceBodyId )
69
-
70
69
this . _startTranslation = new THREE . Vector3 ( 0 , 0 , 0 )
71
70
this . _startRotation = new THREE . Quaternion ( 0 , 0 , 0 , 1 )
72
71
convertJoltMat44ToThreeMatrix4 ( gpBody . GetCenterOfMassTransform ( ) ) . decompose (
@@ -80,7 +79,7 @@ class EjectableSceneObject extends SceneObject {
80
79
81
80
World . physicsSystem . disablePhysicsForBody ( this . _gamePieceBodyId )
82
81
83
- // Remove from scoring zones
82
+ // Remove from any scoring zones
84
83
const zones = [ ...World . sceneRenderer . sceneObjects . entries ( ) ]
85
84
. filter ( x => x [ 1 ] instanceof ScoringZoneSceneObject )
86
85
. map ( x => x [ 1 ] ) as ScoringZoneSceneObject [ ]
@@ -96,7 +95,11 @@ class EjectableSceneObject extends SceneObject {
96
95
public update ( ) : void {
97
96
const now = performance . now ( )
98
97
const elapsed = ( now - this . _animationStartTime ) / 1000
99
- const t = Math . min ( elapsed / this . _animationDuration , 1 )
98
+ const tRaw = elapsed / this . _animationDuration
99
+ const t = Math . min ( tRaw , 1 )
100
+
101
+ // ease-in curve for gradual acceleration
102
+ const easedT = t * t * t
100
103
101
104
if ( this . _parentBodyId && this . _deltaTransformation && this . _gamePieceBodyId ) {
102
105
if ( ! World . physicsSystem . isBodyAdded ( this . _gamePieceBodyId ) ) {
@@ -113,17 +116,23 @@ class EjectableSceneObject extends SceneObject {
113
116
let desiredPosition = new THREE . Vector3 ( 0 , 0 , 0 )
114
117
let desiredRotation = new THREE . Quaternion ( 0 , 0 , 0 , 1 )
115
118
119
+ // Compute target world transform
116
120
const desiredTransform = this . _deltaTransformation
117
121
. clone ( )
118
122
. premultiply ( convertJoltMat44ToThreeMatrix4 ( body . GetWorldTransform ( ) ) )
119
123
120
124
desiredTransform . decompose ( desiredPosition , desiredRotation , new THREE . Vector3 ( 1 , 1 , 1 ) )
121
125
122
126
if ( t < 1 && this . _startTranslation && this . _startRotation ) {
123
- desiredPosition = new THREE . Vector3 ( ) . lerpVectors ( this . _startTranslation , desiredPosition , t )
124
- desiredRotation = new THREE . Quaternion ( ) . copy ( this . _startRotation ) . slerp ( desiredRotation , t )
127
+ // gradual acceleration via easedT
128
+ desiredPosition = new THREE . Vector3 ( ) . lerpVectors ( this . _startTranslation , desiredPosition , easedT )
129
+ desiredRotation = new THREE . Quaternion ( ) . copy ( this . _startRotation ) . slerp ( desiredRotation , easedT )
130
+ } else if ( t >= 1 ) {
131
+ // snap instantly and re-enable physics
132
+ World . physicsSystem . enablePhysicsForBody ( this . _gamePieceBodyId )
125
133
}
126
134
135
+ // apply the transform
127
136
desiredTransform . identity ( ) . compose ( desiredPosition , desiredRotation , new THREE . Vector3 ( 1 , 1 , 1 ) )
128
137
129
138
const bodyTransform = posToCOM . clone ( ) . invert ( ) . premultiply ( desiredTransform )
0 commit comments