Hi all,
I’m using the code bellow to move a movie clip to the mouse coordinates, wich are read on mouse down. The movieclip is facing the motion; the problem is: when it stops, it changes the rotation to increments of 45 degrees, and I would like to preserve the rotation the movieclip has during the motion. I just can’t figure it out…
Please help me if you can. Thank you!
function compDist ( fromX, fromY, toX, toY ){
distX = toX - fromX;
distY = toY - fromY;
ret = Array(
distX,
distY
);
return ret;
}
mc._x = 0;
mc._y = 0;
mc._rotation = 0;
mc.onMouseDown = function(){
toX = _root._xmouse;
toY = _root._ymouse;
}
mc.onEnterFrame = function(){
distArr = compDist(this._x, this._y, toX, toY);
angleTo = Math.atan2(distArr[1], distArr[0]);
//trace (angleTo);
angleToDegs = angleTo * 180 / Math.PI;
angleToDegs -= this._rotation;
while (angleToDegs > 180) angleToDegs -= 360;
while (angleToDegs < -180) angleToDegs += 360;
this._rotation += angleToDegs/2;
moveX = distArr[0]/2;
moveY = distArr[1]/2;
this._x += moveX;
this._y += moveY;
}