# Random movement with easing

**URL:** https://forum.kirupa.com/t/random-movement-with-easing/209225
**Category:** Uncategorized
**Created:** [December 6, 2006, 10:06pm UTC](https://forum.kirupa.com/t/random-movement-with-easing/209225 "2006-12-06T22:06:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Emdiesse](https://avatars.discourse-cdn.com/v4/letter/e/c0e974/32.png) [@Emdiesse](https://forum.kirupa.com/u/Emdiesse)
#### Post date: [December 6, 2006, 10:06pm UTC](https://forum.kirupa.com/t/random-movement-with-easing/209225/1 "2006-12-06T22:06:08Z")

</div>

Hello. I am trying to make some movie clips do random movement with easing.  
I have looked at the mouse follow with easing script here and have tried to adapt it so that it can choose a random x and y and go there.

I have seen the random movement script and I was going to use this and adapt it but I was finding it hard so i looked at the mouse follow with easing for some guidance and wondered why I actually need to calculate the distance, etc and why I can’t just make it so it doesn’t need to calculate the distances.

So I have made this code that to me seems fine but it doesn’t even do the random movement part. why not?

AS for the first frame in the as layer:

```auto

MovieClip.prototype.set = function() 
{
    width = 800; //movie width
    height = 600; //movie height
    this.speed = Math.random()*5+15; //Speed between 5 and 20
    this.targx = Math.random()*width; //New X co-ordination
    this.targy = Math.random()*height; //New y co-ordination
};
MovieClip.prototype.move = function() 
{
    if ((((this._x-this.targx)<10) || ((this.targx-this._x)<10)) && (((this._y-this.targy)<10) || ((this.targy-this._y)<10))) 
    {
        if (!this.t) {
            this.t = getTimer();
        }
        if (getTimer()-this.t>1000) {
            this.set();
            this.t = 0;
        }
    } 
    else 
    {
        this._x += (this.targx-this._x)/this.speed;
        this._y += (this.targy-this._y)/this.speed;
    }
};

```

AS for the movie clip:

```auto

onClipEvent(enterFrame){
    move();
}

```

Any ideas?

Thank you.
