# Shakey shakey movieclips

**URL:** <https://forum.kirupa.com/t/shakey-shakey-movieclips/9677>\
**Category:** Uncategorized\
**Created:** [December 16, 2002, 1:45pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677 "2002-12-16T13:45:48Z")\
**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 16, 2002, 1:45pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/1 "2002-12-16T13:45:48Z")

</div>

I posted a thread and I’ve partly worked out how to do what I need but I still need a slight push in the right direction.

I’ve got two movieclips box and box2 and I’ve place them in the same layer because I couldn’t get each box to move individually in seperate ones I’ve placed this code on the frame

startx = box.\_x;  
starty = box.\_y;  
startx = box2.\_x;  
starty = box2.\_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 dx = \_xmouse-box2.\_x;  
var dy = \_ymouse-box2.\_y;  
var distance = dx_dx+dy\*dy;  
box.shakeYourBody(10000/(distance+1000));  
box2.shakeYourBody(10000/(distance+1000));  
};

Now I’ve got both movieclips shaking but they’re on top of each other rather than in the places I want them. I’m sure its a case of changing something but what?

have a go

Cheers!

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 16, 2002, 2:02pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/2 "2002-12-16T14:02:49Z")

</div>

It’s the first four lines! You are assiging the value of box.\_x to startx and the box.\_y to starty and then you are assining them again but foer the other box!  
Just make it  
startx = box.\_x  
starty = box.\_y  
startx2 = box2.\_x  
startx2 = box2.\_y

but there’s something strange going on there! hwo can you place that first code on a frame if there are lines which start with “this.”.  
there shoud be scripts on both of the boxes… :-\

---

<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 16, 2002, 2:13pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/3 "2002-12-16T14:13:45Z")

</div>

Nope, the problem is that you overwrite dx and dy.

```auto
this.onEnterFrame = function() {
  // Find distance
  var dx = _xmouse-box._x;
  var dy = _ymouse-box._y;
  var distance = dx*dx+dy*dy;
  box.shakeYourBody(10000/(distance+1000));

  var dx = _xmouse-box2._x;
  var dy = _ymouse-box2._y;
  var distance = dx*dx+dy*dy;
  box.shakeYourBody(10000/(distance+1000));
  box2.shakeYourBody(10000/(distance+1000));
};

```

Syko\>\> What’s wrong with this on a frame?

pom \<:}

---

<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 16, 2002, 2:21pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/4 "2002-12-16T14:21:18Z")

</div>

I’ve changed the script to this as ilyaslamasse posted but the two boxs are still on top of each other when I publish the movie…even thought they are on the other side of the screen to eachother.

startx = box.\_x;  
starty = box.\_y;  
startx = box2.\_x;  
starty = box2.\_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(10000/(distance+1000));  
var dx = \_xmouse-box2.\_x;  
var dy = \_ymouse-box2.\_y;  
var distance = dx_dx+dy\*dy;  
box2.shakeYourBody(10000/(distance+1000));  
};  
:-\

---

<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 16, 2002, 2:46pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/5 "2002-12-16T14:46:47Z")

</div>

True, I didn’t notice that you had overwritten startx and starty too. Gimme a second.

---

<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 16, 2002, 2:51pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/6 "2002-12-16T14:51:13Z")

</div>

```auto
box.startx = box._x;
box.starty = box._y;
box2.startx = box2._x;
box2.starty = box2._y;
MovieClip.prototype.shakeYourBody = function(radius) {
	forceX = 2*(Math.random()-.5)*radius;
	forceY = 2*(Math.random()-.5)*radius;
	this._x = this.startx+forceX;
	this._y = this.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(10000/(distance+1000));
	var dx = _xmouse-box2._x;
	var dy = _ymouse-box2._y;
	var distance = dx*dx+dy*dy;
	box2.shakeYourBody(10000/(distance+1000));
};

```

I put startx and starty as a property of the boxes.

pom 🙂

---

<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 16, 2002, 4:45pm UTC](https://forum.kirupa.com/t/shakey-shakey-movieclips/9677/7 "2002-12-16T16:45:27Z")

</div>

> Syko\>\> What’s wrong with this on a frame?

nothing 🙂 I wasn’t thinking clearly… I was gonna delete that line but I forgot! 😛  
hehe
