# Movement function

**URL:** <https://forum.kirupa.com/t/movement-function/218427>\
**Category:** Uncategorized\
**Created:** [March 7, 2007, 5:25pm UTC](https://forum.kirupa.com/t/movement-function/218427 "2007-03-07T17:25:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Macsy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/macsy/32/3238_2.png) [@Macsy](https://forum.kirupa.com/u/Macsy)\
**Post date:** [March 7, 2007, 5:25pm UTC](https://forum.kirupa.com/t/movement-function/218427/1 "2007-03-07T17:25:40Z")

</div>

My code wont work as i want to.  
My target MC jumps back and forth when it reaches the endX and endY… Please?

```auto
movement = function (moveIsActive, target, endX, endY) {
    if (moveIsActive) {
        a = Math.atan2(endY-target._y, endX-target._x);
        target._x += Math.cos(a)*speed;
        target._y += Math.sin(a)*speed;
        if (target._x==endX) {
            if (target._y==endY) {
                moveIsActive = false;
            }
        }
    } else {
    }
};

```
