Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    43
    Thanks
    8
    Thanked 0 Times in 0 Posts

    JS, Move coord 1 toward coord 2

    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);
    Last edited by nuBee; 12-14-2011 at 10:49 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •