# Wibble wobble to mouse

**URL:** <https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529>\
**Category:** Uncategorized\
**Created:** [December 13, 2002, 12:18pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529 "2002-12-13T12:18:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![postatomic](https://avatars.discourse-cdn.com/v4/letter/p/c68b51/32.png) [@postatomic](https://forum.kirupa.com/u/postatomic)\
**Post date:** [December 13, 2002, 12:18pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/1 "2002-12-13T12:18:42Z")

</div>

I want to have a square on my web page which is static until the mouse gets closer. as the mouse gets to a certain distance the box begins to shake, then shakes less when the mouse gets further away.  
Does anyone know how to achieve this???  
cheers  
🙂

---

<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:** [December 13, 2002, 12:22pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/2 "2002-12-13T12:22:32Z")

</div>

You mean some kind of proximity detector? Yeah, I’m sure that’s possible. You’d have to monitor the \_x and \_y properies of the cursor, then compare it to those of your box MC… As the number start to get coser together, you shake the box… I’d need a little time to work it out scripting-wise, but I’m sure a genuis like Ilyas could figure out the code. 🙂

---

<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:** [December 13, 2002, 12:42pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/3 "2002-12-13T12:42:06Z")

</div>

thad would be a need tutorial:q:

---

<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:** [December 13, 2002, 1:09pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/4 "2002-12-13T13:09:01Z")

</div>

Oh, yeah 🙂

Mebbe I’ll try and make something similar… not a tut, just trying it… 🙂

---

<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:** [December 13, 2002, 1:09pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/5 "2002-12-13T13:09:49Z")

</div>

If you have a clip called _box_ on the scene, you can try that kind of code:

```auto
startx=box._x;
starty=box._y;
MovieClip.prototype.shakeYourBody=function(radius){
	forceX=2*(Math.random()-.5)*radius;
	forceY=2*(Math.random()-.5)*radius;
	this._x=startx+forceX;
	this._y=starty+forceY;
}

this.onEnterFrame=function(){
	// Find distance
	var dx=_xmouse-box._x;
	var dy=_ymouse-box._y;
	var distance=dx*dx+dy*dy;
	box.shakeYourBody(100000/(distance+10));
}

```

I don’t have time to explain right now, sorry :-\

pom :crazy:

---

<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:** [December 13, 2002, 1:36pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/6 "2002-12-13T13:36:11Z")

</div>

cheeeeeers everyone for the interest…thanks for the code aswell!!

😛

postatomic

---

<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:** [December 13, 2002, 6:41pm UTC](https://forum.kirupa.com/t/wibble-wobble-to-mouse/9529/7 "2002-12-13T18:41:10Z")

</div>

Ok…  
I’ve tried more than one box (infact three) and named them all different and changed the code to match each clip but only the first one works…if I delete the first one then the rest work?? strange…work that one out…hehe
