i use setinterval to loop and to move the object with the following code, it work and it move to bottom left, but when the location is at the bottom right it didnt work, here is the code
if(pass._x > x && pass._y < y)
{ang = Math.atan2(y-pass._y, x- pass._x);
if (pass._x > x)
{
pass._x += Math.cos(ang)*spe/15;
pass._y += Math.sin(ang)*spe/15;
}
}
else if (pass._x < x && pass._y < y)
{ang = Math.atan2(y-pass._y, x - pass._x);
if (pass._x < x)
{
pass._x += Math.cos(ang)*spe/15;
pass._y += Math.sin(ang)*spe/15;
}
}
when the x is negative value and y is positive value it work (move to bottom left), when x is positive value and y is positive value, it didnt work , (should move to bottom right). any idea?? thanks