@dnode/move.2d

2.0.2 • Public • Published

dependencies | 0 | 0

Usage

Get a single move of the object to the target

const getMove = require('@dnode/move.2d');

const objectPosition = { x: -1, y: 5 };
const objectSpeed = 5;
const targetPosition = { x: 10, y: -10 };

const move = getMove(objectPosition, objectSpeed, targetPosition);

Move the object till it arrives the target

const getMove = require('@dnode/move.2d');

const objectPosition = { x: 10, y: -10 };
const objectSpeed = 20;
const targetPosition = { x: 800, y: 700 };

let move;
do {
  move = getMove(objectPosition, objectSpeed, targetPosition);
  objectPosition.x += move.x;
  objectPosition.y += move.y;
} while (move.move && !move.arrive);

Readme

Keywords

none

Package Sidebar

Install

npm i @dnode/move.2d

Weekly Downloads

3

Version

2.0.2

License

MIT

Last publish

Collaborators

  • sharaal