# Moving object problem

**URL:** <https://forum.kirupa.com/t/moving-object-problem/198438>\
**Category:** flash\
**Created:** [August 25, 2006, 2:01am UTC](https://forum.kirupa.com/t/moving-object-problem/198438 "2006-08-25T02:01:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daytonatkf](https://avatars.discourse-cdn.com/v4/letter/d/9fc29f/32.png) [@daytonatkf](https://forum.kirupa.com/u/daytonatkf)\
**Post date:** [August 25, 2006, 2:01am UTC](https://forum.kirupa.com/t/moving-object-problem/198438/1 "2006-08-25T02:01:39Z")

</div>

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
