* return the distance to the specified target * @param {Renderable|Vector2d|Vector3d} target * @returns {number} distance
(target)
| 662 | * @returns {number} distance |
| 663 | */ |
| 664 | distanceTo(target) { |
| 665 | const a = this.getBounds(); |
| 666 | let dx; |
| 667 | let dy; |
| 668 | |
| 669 | if (target instanceof Renderable) { |
| 670 | const b = target.getBounds(); |
| 671 | dx = a.centerX - b.centerX; |
| 672 | dy = a.centerY - b.centerY; |
| 673 | } else { |
| 674 | // vector object |
| 675 | dx = a.centerX - target.x; |
| 676 | dy = a.centerY - target.y; |
| 677 | } |
| 678 | |
| 679 | return Math.sqrt(dx * dx + dy * dy); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * Rotate this renderable towards the given target. |