# Repel away from mouse

**URL:** <https://forum.kirupa.com/t/repel-away-from-mouse/237279>\
**Category:** flash\
**Created:** [August 28, 2007, 9:57pm UTC](https://forum.kirupa.com/t/repel-away-from-mouse/237279 "2007-08-28T21:57:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigbstanley](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@bigbstanley](https://forum.kirupa.com/u/bigbstanley)\
**Post date:** [August 28, 2007, 9:57pm UTC](https://forum.kirupa.com/t/repel-away-from-mouse/237279/1 "2007-08-28T21:57:24Z")

</div>

I’ve been trying to come up with a script that will make mc’s repel away from the mouse. Here is an example of exactly what I’m looking for:

[http://www.antstudio-bcn.com/](http://www.antstudio-bcn.com/)

and here is the beginning of a script that I’ve modified from Kirupa to try and achieve this effect, but it looks terrible.

```auto

this.createEmptyMovieClip("dot", -10) ;
dot.lineStyle (10, 0, 100) ;
dot.lineTo (.45, .15) ;
dot._visible = false ;

count=0;
k = .09;
minDist = 50;
damp = .9;

function repelMouse() {
    
    var dx = _xmouse - this._x;
    var dy = _ymouse - this._y;
    var d = Math.sqrt(dx*dx + dy*dy);
    
    if (d <= minDist) {
        this._x -= dx / d * minDist * k;
        this._y -= dy / d * minDist * k;
    }   
   
       if (d > minDist + 5){
        this.vx = (this.myX - this._x) * .5;
           this.vy = (this.myY - this._y) * .5;
           this._x += this.vx;
           this._y += this.vy;
    }
}

for (var i=0; i < 10; i++) {
    for (var j=0; j < 10; j++) {
        count++ ;
        var d = dot.duplicateMovieClip ("d"+count, count) ;
        d._x = d.myX = 30 * i ;
        d._y = d.myY = 30 * j ;
        d.onEnterFrame = repelMouse;
    }
}

```

the dots seem so jumpy. there has to be a better way to do this. I’ve looked online, and everything i found was ridiculously complicated. any help would be greatly appreciated.
