...

View Full Version : JS, Move coord 1 toward coord 2



nuBee
12-14-2011, 09:17 PM
solved::

if anyone making games needs a simple pathing between 2 points its:



function getPlayer() {
var Angle = Math.atan2( hero.x - monster.x, hero.y - monster.y);
var Per_Frame_Distance = 15;
var Sin = Math.sin(Angle) * Per_Frame_Distance;
var Cos = Math.cos(Angle) * Per_Frame_Distance;

monster.x += Sin;
monster.y += Cos;
}

var attack = setInterval(getPlayer, 1000);


The documentation I found it from had it posted incorrectly with
var Angle = Math.atan2(hero.y - monster.y, hero.x - monster.x);

Correct way was:
var Angle = Math.atan2( hero.x - monster.x, hero.y - monster.y);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum