I need help to make my ragdoll funciton better.
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?