# Remove random motion

**URL:** <https://forum.kirupa.com/t/remove-random-motion/311071>\
**Category:** flash\
**Created:** [June 26, 2010, 11:30pm UTC](https://forum.kirupa.com/t/remove-random-motion/311071 "2010-06-26T23:30:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imcabee](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@imcabee](https://forum.kirupa.com/u/imcabee)\
**Post date:** [June 26, 2010, 11:30pm UTC](https://forum.kirupa.com/t/remove-random-motion/311071/1 "2010-06-26T23:30:54Z")

</div>

I have a random motion script that I need to remove when the object in random motion hovers over a specific area in the background. I need the object to just keep moving in the direction it was going in and not randomly switch directions or bounce.

This is my script for the random motion which is on the object:

```auto
onClipEvent (load) {
    //data you may want to change
    width = 1100;
    height = 800;
    speed =1;
    //initial positions
    x = Math.random()*width;
    y = Math.random()*height;
    this._x = x;
    this._y = y;
    x_new = Math.random()*width;
    y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
    //x movement
    if (x_new>this._x) {
        sign_x = 1;
    } else {
        sign_x = -1;
    }
    dx = Math.abs(x_new-this._x);
    if ((dx>speed) || (dx<-speed)) {
        this._x += sign_x*speed;
    } else {
        x_new = Math.random()*width;
    }
    //y movement
    if (y_new>this._y) {
        sign_y = 1;
    } else {
        sign_y = -1;
    }
    dy = Math.abs(y_new-this._y);
    if ((dy>speed) || (dy<-speed)) {
        this._y += sign_y*speed;
    } else {
        y_new = Math.random()*height;
    }
}

```

Any help would be greatly appreciated, thanks!
