Elastic mouse follower - Flash

create a movieclip give it the instance name sam and put this code on the timeline

// Create and initialize some variables

distx = 0;
disty = 0;
momentumx = 0;
momentumy = 0;

_root.sam.onEnterFrame = function() {
// follow the mouse in a more elastic way
// by using momentum


distx = sam._x - _xmouse;
disty = sam._y - _ymouse;
momentumx -= distx / 200;
momentumy -= disty / 200;

// dampen the momentum a little

momentumx *= 0.95;
momentumy *= 0.95;

// go get that mouse!

sam._x += momentumx;
sam._y += momentumy;
}