Simple Mouse follower
Place this scripts inside the object to
follow the mouse.
frame 1:
physics = 0.5
frame 2:
// nothing in here
frame 3:
// add parts of the distance between
// the mouse and me, the object to follow.
_x += (_root._xmouse-_x)*physics;
_y += (_root._ymouse-_y)*physics;
gotoAndPlay(2);
In Flash 5 you can alternatively use
onClipEvent(enterFrame) to make this
script work.
onClipEvent(load){
physics = 0.5;
}
onClipEvent(enterFrame){
_x += (_root._xmouse-_x)*physics;
_y += (_root._ymouse-_y)*physics;
}
- dwid Date: 03/04/2003
in MX you can do it short and simple.
place the code in the following movieclips
timeline:
-------------------------------------------
stop();
var physics = .2;
this.onEnterFrame = function(){
this._x += (_root._xmouse-this._x)*physics;
this._y += (_root._ymouse-this._y)*physics;
}
should work the same way, right?
- Biotech Date: 08/05/2003
There is a subtle error in this script.
Because _x is defined to be the x offset of
this object from its parent, the script that
you presented fails if the object which is
supposed to follow the mouse is not a direct
child of the _root, provided that any one of
its ancestors is not at (0, 0).
The correct script would be:
_x += ( _parent._xmouse - _x ) * physics;
_y += ( _parent._ymouse - _y ) * physics;
Add comment
Home