Mouse approach
Code Actionscript 2.0
Instance action
onClipEvent (enterFrame) {
softness = 8.0;
targetx = _root._xmouse;
this._x = this._x + (targetx - this._x) / softness;
}
Code Actionscript 3.0
addEventListener(Event.ENTER_FRAME, enterFrame); function enterFrame(event:Event) { var softness = 8.0; var targetx = mouseX; square.x = square.x + (targetx - square.x)/ softness; }
Description
The square follows the mouse with a slight delay. Tracking the horizontal mouse-coordinate, it approaches the target with a smooth movement determined by the variable softness.
related to: Movement towards a target, Mouse position
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File