|
@@ -19,6 +19,9 @@ const ANIMATION_DURATION = 3.0;
|
19
|
19
|
/** Duration of the fade-out effect, in seconds */
|
20
|
20
|
const FADE_OUT_DURATION = 1.0;
|
21
|
21
|
|
|
22
|
+/** Y offset from the hoop, in world units */
|
|
23
|
+const Y_OFFSET = 0.25;
|
|
24
|
+
|
22
|
25
|
/**
|
23
|
26
|
* Score Text
|
24
|
27
|
*/
|
|
@@ -129,37 +132,18 @@ export class ScoreText extends Entity
|
129
|
132
|
}
|
130
|
133
|
|
131
|
134
|
/**
|
132
|
|
- * Find the geometrical center, in world space, of a set of hooks
|
133
|
|
- * @param {BABYLON.Mesh[]} hooks non-empty array
|
134
|
|
- * @returns {BABYLON.Vector3}
|
135
|
|
- */
|
136
|
|
- _findCenter(hooks)
|
137
|
|
- {
|
138
|
|
- const center = new BABYLON.Vector3(0, 0, 0);
|
139
|
|
-
|
140
|
|
- for(const hook of hooks) {
|
141
|
|
- center.x += hook.absolutePosition.x;
|
142
|
|
- center.y += hook.absolutePosition.y;
|
143
|
|
- center.z += hook.absolutePosition.z;
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- return center.scaleInPlace(1 / hooks.length);
|
147
|
|
- }
|
148
|
|
-
|
149
|
|
- /**
|
150
|
135
|
* Handle an event
|
151
|
136
|
* @param {GameEvent} event
|
152
|
137
|
* @returns {void}
|
153
|
138
|
*/
|
154
|
139
|
handleEvent(event)
|
155
|
140
|
{
|
156
|
|
- if(event.type == 'hooksready') {
|
157
|
|
- const hooks = event.detail.hooks;
|
158
|
|
- const center = this._findCenter(hooks);
|
159
|
|
- const parent = this._mesh.parent;
|
160
|
|
- const offset = center.subtract(parent.absolutePosition);
|
|
141
|
+ if(event.type == 'hoopready') {
|
|
142
|
+ const hoopPosition = event.detail.position;
|
|
143
|
+ const offset = new BABYLON.Vector3(0, Y_OFFSET, 0);
|
|
144
|
+ const position = hoopPosition.add(offset);
|
161
|
145
|
|
162
|
|
- this._initialPosition.copyFrom(offset);
|
|
146
|
+ this._initialPosition.copyFrom(position);
|
163
|
147
|
this._mesh.position.copyFrom(this._initialPosition);
|
164
|
148
|
}
|
165
|
149
|
else if(event.type == 'scored') {
|