Symbios
Symbios

Reputation: 17

Move object towards coordinates

Lets say I have a var speed = 2;, var x = 2; and var y = 3;.
I want my div element var char = document.getElementById('character'); to approach the variables X and Y. How would I do this?

Upvotes: 0

Views: 72

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 8945

Basic trigonometric functions such as atan[2]() can tell you the angle from “here” to “there,” and Mr. Pythagoras can supply the distance.   Whatever algorithm you wish to supply for “approach,” (including, very specifically, any incomplete-ness or uncertainty regarding that ‘approach,’” is of course entirely up to you . . .

Upvotes: 1

Related Questions