# Help with motion

**URL:** https://forum.kirupa.com/t/help-with-motion/160937
**Category:** Uncategorized
**Created:** [August 30, 2005, 8:30pm UTC](https://forum.kirupa.com/t/help-with-motion/160937 "2005-08-30T20:30:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ApixDesigns](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@ApixDesigns](https://forum.kirupa.com/u/ApixDesigns)
#### Post date: [August 30, 2005, 8:30pm UTC](https://forum.kirupa.com/t/help-with-motion/160937/1 "2005-08-30T20:30:35Z")

</div>

ok so i did the tutorial that kirupa put up, but now i am wondering how i can edit the code so that i can have random speeds aswell, i just used the code that they ahve written. please help!

```auto
 onClipEvent (load) {
 //data you may want to change
 width = 700;
 height = 600;
 speed = Math.round(Math.random()*1)+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;
 }
}
 

```
