# Stuck with random motion - Help please

**URL:** <https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342>\
**Category:** design\
**Created:** [April 12, 2006, 4:55pm UTC](https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342 "2006-04-12T16:55:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriindira](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@sriindira](https://forum.kirupa.com/u/sriindira)\
**Post date:** [April 12, 2006, 4:55pm UTC](https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342/1 "2006-04-12T16:55:11Z")

</div>

Iam a newbie to forums and i have been trying out the random tutorial given by kirpua here  
[http://www.kirupa.com/developer/actionscript/random\_motion.htm](http://www.kirupa.com/developer/actionscript/random_motion.htm)

however i tried to modify the code and add my own scripting a little bit but though i feel the logic behind the code is correct i dont know why the movie clip moves in a erratic manner

can anyone pls help me

This is the code

![]()onClipEvent (load) {

//data you may want to change  
width = 500;  
height = 500;  
speed = Math.random()\*2;  
//initial positions  
this.\_x=Math.random()\*width;  
this.\_y=Math.random()\*height;  
x\_new = Math.random()\*width;  
y\_new = Math.random()\*height;

}  
onClipEvent (enterFrame){  
if(this.\_x\<x\_new)this.\_x+=speed; // checking if current position is \< than the final position then move the movie clip forward  
if(this.\_x\>x\_new)this.\_x-=speed; // // checking if current position is \> than the final position then move the movie clip backward  
if(this.\_x=x\_new)  
{  
x\_new = Math.random()\*width;// if they are both same then assign new end value  
}  
}

as the clip moves forward and when its pos becomes equal to the final pos i randmly change the value of the final movie clip position in that case that final position may be greater than or less than the this.\_x if its lesser it will follow the first loop else if its greater it will follow the second loop

the movie clip keeps bouncing across the screen and moves very fast

Can someone help me :h:

---

<div class="post-metadata">

**Author:** ![michael1](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@michael1](https://forum.kirupa.com/u/michael1)\
**Post date:** [April 12, 2006, 5:26pm UTC](https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342/2 "2006-04-12T17:26:51Z")

</div>

> [@sriindira](#):
>
> Iam a newbie to forums and i have been trying out the random tutorial given by kirpua here  
> [http://www.kirupa.com/developer/actionscript/random\_motion.htm](http://www.kirupa.com/developer/actionscript/random_motion.htm)
> 
> however i tried to modify the code and add my own scripting a little bit but though i feel the logic behind the code is correct i dont know why the movie clip moves in a erratic manner
> 
> can anyone pls help me
> 
> This is the code
> 
> ![]()onClipEvent (load) {
> 
> //data you may want to change  
> width = 500;  
> height = 500;  
> speed = Math.random()\*2;  
> //initial positions  
> this.\_x=Math.random()\*width;  
> this.\_y=Math.random()\*height;  
> x\_new = Math.random()\*width;  
> y\_new = Math.random()\*height;
> 
> }  
> onClipEvent (enterFrame){  
> if(this.\_x\<x\_new)this.\_x+=speed; // checking if current position is \< than the final position then move the movie clip forward  
> if(this.\_x\>x\_new)this.\_x-=speed; // // checking if current position is \> than the final position then move the movie clip backward  
> if(this.\_x=x\_new)  
> {  
> x\_new = Math.random()\*width;// if they are both same then assign new end value  
> }  
> }
> 
> as the clip moves forward and when its pos becomes equal to the final pos i randmly change the value of the final movie clip position in that case that final position may be greater than or less than the this.\_x if its lesser it will follow the first loop else if its greater it will follow the second loop
> 
> the movie clip keeps bouncing across the screen and moves very fast
> 
> Can someone help me :h:

wrong forum 😃 // Sorry I’m not help for your dilemma.

---

<div class="post-metadata">

**Author:** ![hybrid101](https://avatars.discourse-cdn.com/v4/letter/h/7993a0/32.png) [@hybrid101](https://forum.kirupa.com/u/hybrid101)\
**Post date:** [April 13, 2006, 5:56am UTC](https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342/3 "2006-04-13T05:56:33Z")

</div>

should be in the flash forums man. can a mod please move this?

---

<div class="post-metadata">

**Author:** ![simplistik](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/simplistik/32/7747_2.png) [@simplistik](https://forum.kirupa.com/u/simplistik)\
**Post date:** [April 13, 2006, 5:58am UTC](https://forum.kirupa.com/t/stuck-with-random-motion-help-please/185342/4 "2006-04-13T05:58:32Z")

</div>

done
