MCPcopy Create free account
hub / github.com/melonjs/melonJS / distanceTo

Method distanceTo

packages/melonjs/src/renderable/renderable.js:664–680  ·  view source on GitHub ↗

* return the distance to the specified target * @param {Renderable|Vector2d|Vector3d} target * @returns {number} distance

(target)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 2

getBoundsMethod · 0.95
getBoundsMethod · 0.65

Tested by

no test coverage detected