Monday, April 6, 2009

Flash: rotate object following mouse

Reader Rating: 6.6

1. Create a movieclip as you prefer. then give the movieclip an instance name --example my instance name : 'follower'.

2. On first frame, insert the following action:

//sets the speed of rotation
rotation_speed = 5;
//sets the elasticity the higher the value the higher the elasticity
elasticity = .1;
_root.onEnterFrame = function()
{
 with (follower) {
   _rotation += rotation_speed;
   _x += (_root._xmouse-_x)*elasticity;
   _y += (_root._ymouse-_y)*elasticity;
 }
};

You are done,  Test the movie. Remember, you can increase the rotation_speed variable to create different effects.

0 comments:

Post a Comment