# Random movement question

**URL:** <https://forum.kirupa.com/t/random-movement-question/15350>\
**Category:** flash\
**Created:** [March 13, 2003, 6:52am UTC](https://forum.kirupa.com/t/random-movement-question/15350 "2003-03-13T06:52:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pares101](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@pares101](https://forum.kirupa.com/u/pares101)\
**Post date:** [March 13, 2003, 6:52am UTC](https://forum.kirupa.com/t/random-movement-question/15350/1 "2003-03-13T06:52:33Z")

</div>

Hey i have this code i understand somewhat

```php

MovieClip.prototype.moveMe = function(begin, end, speed) {
    if (this._x<=end) {
        this._x += speed;
    } else {
        this._x = begin;
        this._y = Math.random()*(64.5-0.5)+5;
    }
};

```

and the movieClip

```php

onClipEvent (load) {
	
	this._y = Math.random()*(64.5-0.5)-5;
	var begin1 = (0 - (this._width / 2))
	var end1 = (Stage.width + (this._width / 2))
	var speed1 = Math.round (((Math.random() * 4) + 1))
}
onClipEvent (enterFrame) {
	this.moveMe (begin1, end1, speed1)
}

```

this moves along the X axis at a random speed / y axis

now how do invert it to make it go random on the Y axis with the stage width being 445y , 0y and 441x, 750x man all this math/coding fries my brain!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 13, 2003, 7:04am UTC](https://forum.kirupa.com/t/random-movement-question/15350/2 "2003-03-13T07:04:01Z")

</div>

Well if its moving on the \_x and having the \_y random, then just switch the \_x’s and the \_y’s in the scripts.

That way the \_y will be moving and the \_x will be random.
