Hi,
I want to make a movie that follows the mouse, but only if the mouse gets further than 50 pixels away from it.
Making the movie follow the mouse is easy. The thing making my head hurt is getting the movie to return to the right place when the mouse moves more than 50 pixels away.
this is my code now.
onClipEvent(enterFrame) {
var xval
var yval
var lastx
var lasty
var speed = 7
xval = _root._xmouse;
yval = _root._ymouse;
if (Math.abs(lastx-xval)>50 ) {
this._x += ((xval+20)-lastx)/speed;
}
if (Math.abs(lasty-yval)>50 ) {
this._y += ((yval-20)-lasty)/speed;
}
lastx = this._x
lasty = this._y
}
And it works, except as soon as the movie gets within 50 pixels of the mouse, it stops. I want it to end up 20 pixels above and to the left of the mouse. And the movie has smooth movement in one direction, but the opposite direction is jumpy.
I know that once the distance from movie to mouse is less than 50, it is not being told to move anymore. How do I get that lazy movie clip back to it’s rightful spot?