# Ragdoll function

**URL:** <https://forum.kirupa.com/t/ragdoll-function/210144>\
**Category:** flash\
**Created:** [December 15, 2006, 11:48am UTC](https://forum.kirupa.com/t/ragdoll-function/210144 "2006-12-15T11:48:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pattt](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@Pattt](https://forum.kirupa.com/u/Pattt)\
**Post date:** [December 15, 2006, 11:48am UTC](https://forum.kirupa.com/t/ragdoll-function/210144/1 "2006-12-15T11:48:40Z")

</div>

I need help to make my ragdoll funciton better.

```auto
 
function link(ob1, ob2, len) {
 // -------------ragdoll--------------  
 var dx = ob2._x-ob1._x;
 var dy = ob2._y-ob1._y;
 // ------------------------------------- 
 var alpha = Math.atan2(dy, dx);
 nx = ob1._x+Math.cos(alpha)*len;
 ny = ob1._y+Math.sin(alpha)*len;
 // -------------------------------------  
 di = 5;
 ob1.xx -= (nx-ob2._x)/di;
 ob1.yy -= (ny-ob2._y)/di;
 ob2.xx += (nx-ob2._x)/di;
 ob2.yy += (ny-ob2._y)/di;
// xx = xspeed, yy = yspeed
}
ob1.xx=ob1.yy=ob2.xx=ob2.yy=0;
this.onEnterFrame = function() {
ob1._x+=ob1.xx
ob1._y+=ob1.yy
ob2._x+=ob2.xx
ob2._y+=ob2.yy
link(ob1, ob2, 20)
}
 

```

If you link two mcs with this function, it will be quite elastic.  
How can I improve it? Make it better?
