Просмотр исходного кода

Basketball game: more adjustments

customisations
alemart 8 месяцев назад
Родитель
Сommit
56a18c9b2e
1 измененных файлов: 7 добавлений и 6 удалений
  1. 7
    6
      demos/basketball/src/entities/ball.js

+ 7
- 6
demos/basketball/src/entities/ball.js Просмотреть файл

@@ -34,7 +34,7 @@ const PLANE_BALL_OFFSET = -0.35;
34 34
 /** Maximum distance from the camera to the ball, so that the ball is considered "lost" in the thrown state */
35 35
 const MAX_DISTANCE = 15;
36 36
 
37
-/** Maximum distance in the y-axis from the camera to the ball, so that the ball is considered "lost" in the thrown state */
37
+/** Maximum distance in the y-axis from ar.root to the ball, so that the ball is considered "lost" in the thrown state */
38 38
 const MAX_Y_DISTANCE = 5;
39 39
 
40 40
 /** Frequency of the shining effect, in Hz */
@@ -412,19 +412,20 @@ export class Ball extends Entity
412 412
             return 0;
413 413
         }
414 414
 
415
-        const time = this.ar.session.time;
416
-        const dt = time.delta;
415
+        const ar = this.ar;
416
+        const dt = ar.session.time.delta;
417 417
         const rate = 1.0 / SHINE_FADE_DURATION;
418 418
         const distance = this._calculateDistanceToHoop(this._mesh.absolutePosition);
419 419
 
420
+        // shine if long distance
420 421
         if(distance >= THREE_POINT_THRESHOLD) {
421 422
             this._shineFactor = 1;
422 423
             this._shineTimer += dt;
423 424
         }
424 425
         else {
425
-            this._shineFactor = Math.max(0, this._shineFactor - rate * dt);
426
-            if(this._shineFactor == 0)
427
-                this._shineTimer = 0;
426
+            this._shineFactor -= rate * dt;
427
+            if(this._shineFactor <= 0)
428
+                this._shineFactor = this._shineTimer = 0;
428 429
         }
429 430
 
430 431
         const t = this._shineTimer;

Загрузка…
Отмена
Сохранить