Monday, May 2, 2011

Object in flash that follows mouse

1. Create a simple movie clip with registration point from where you want it to rotate.

2. Select the movie clip and paste the below given script onto that

onClipEvent (enterFrame) {
myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
 myDegrees = Math.round((myRadians*180/Math.PI));
 _root.yChange = Math.round(_root._ymouse-this._y);
 _root.xChange = Math.round(_root._xmouse-this._x);
 _root.yMove = Math.round(_root.yChange/20);
 _root.xMove = Math.round(_root.xChange/20);
 this._y += _root.yMove;
 this._x += _root.xMove;
 this._rotation = myDegrees+90;
}

That’s it you are done.

No comments:

Post a Comment