Elastic mouse follower

Place this scripts inside the object to follow the mouse. Basically the distance between the mouse and the object is diminished. frame 1: physics0 = 0.25; physics1 = 0.5; frame 2: // nothing in here frame 3: xspeed = ((_root._xmouse-_x)*physics0)+(xspeed*physics1); yspeed = ((_root._ymouse-_y)*physics0)+(yspeed*physics1); // add the speed to the current position of the object _x += xspeed; _y += yspeed; gotoAndPlay(2);
Jared Bartlett Date: 10/04/2001

I\'ve been trying to make your code work, It seems I\'m having a problem where the object doesn\'t follow my mouse but rather floats off the page. please help Jared
bokel Date: 15/04/2001

I just checked the code, and everything seems to be okay. Make sure you place the script inside a movie object. This should be the object which follows the mouse.
Joe Date: 05/05/2001

Bokel, I have Flash 4. What modifications do I need to make to achieve the same effect? Any Ideas? Joe
Joe Date: 05/05/2001

I found your reply to this question on Macromedia\'s message board. Thanks bokel. Joe
bravo Date: 10/07/2001

add the speed to the difference in position between the mouse and me, the object to follow. Place this scripts inside the object to follow the mouse. what do you mean with this? please explain it to me step by step. i even don\'t understand this: Place this scripts -inside- the object to follow the mouse. mzzl bravo
eugeni Date: 20/11/2001
you can simply put in a movie inside root timeline this: onClipEvent (load) { physics0 = 0.25; physics1 = 0.5; } onClipEvent (enterFrame) { xspeed = ((_root._xmouse-_x)*physics0)+(xspeed*physics1); yspeed = ((_root._ymouse-_y)*physics0)+(yspeed*physics1); _x += xspeed; _y += yspeed; } :) ------- thanks eugeni, your posting made me think again about this script: i changed the _parent to _root, so we can place our object at any timeline. moreover i replaced the array physics with two variables physics0 and physics1 to optimize speed. bokel -------
Paeterman Date: 03/12/2001
Very nice Script... you should add a _alha fading efx: as near as the object is (to mouse) as _alpha< mfg Paeterman www.waterflash.de
alostorah Date: 05/10/2002
very wonderful code i tried it it is nice really thanks alot
Melissa Date: 05/11/2002
im a high school student at a technology school and im learning how to build my own website, but im still just a beginner and the whole html things is still a little weird to me, but my question is if this code goes with the rest of the html codes in notepad and where do i put it? Thanx, Melissa
kirkup Date: 15/01/2003
i am new to all this web site stuff and i was wondering do i need to get an image my self and were the fu** do i paste the code i aint got a clue can any 1 help
Rob3d Date: 25/01/2003
Melissa... this is code for flash... you cant use it in the html. i rekommend that you leave html and that shit in the corner and start learning yourself Flash. you can do very cool sites with it and have lots of effects... and most amazing with flash... the page wont be bigger than few (houndred) (kilo)bytes. and its pretty simple to make a newbie site... so try flash .... and you'll stick to it :) // www.rob3d.com
TxarŠn Date: 04/03/2003
for some reason I had to ad +10 to have my object follow the exact place of mouse onClipEvent(load){ physics = 0.5; } onClipEvent(enterFrame){ _x += (_root._xmouse-_x)*physics+10; _y += (_root._ymouse-_y)*physics; }
godchylde Date: 16/11/2003
not too shabby.... that's a damn easy tutorial...
Danny Date: 26/01/2004
im using this in flash mx on a movie clip on the main stage the movie clip has links in it the movie clip has this action onClipEvent (load) { friction = .4 ratio = .3 speed = 0 } onClipEvent (enterFrame) { speed = (speed*friction)+((ypos-_y)*ratio) pos = this._y+200 this._y = pos+speed } and blank buttons on a dif layer with this action on (rollOver) { _root.triangle.ypos = -120; } the link has the action on (release) {getURL("rules.htm" , "_self", "get"); } the browser says .../rules.htm?friction=0%2E4&ratio=0%2E3&speed=%2D199%2E975&pos=599%2E95 and on another link /downloads.htm i get a page cannot be displayed but when i refresh its fine can you help me please?
this was the problem Date: 26/01/2004
on (release) { if(this.hitTest(_root._xmouse,_root._ymouse,true)){ getURL("rules.htm"); } }
mouse anywhere Date: 15/02/2004
can i do this so the object will follow this mouse whether the mouse is over the actual movie or not? like anywhere on the webpage jeffrey
Shakti Date: 26/07/2004
I am new to all this stuff and couldn't figure out where to place the code and see the effect.
atorrijos Date: 08/08/2004
I had a little problem getting the original frame scripts to work. I haven't gotten the onClipEvent script to work yet when publishing to Flash Player 7.0 using ActionScript 2.0(File>Publish Settings). They work when published for Flash Player 6 using ActionScript 2.0. I had to define the _xspeed and _yspeed in the first frame to get it to work for Flash Player 7. //Code on first frame of MovieClip symbol var physics0:Number = 0.25; var physics1:Number = 0.5; var xspeed:Number = 0; var yspeed:Number = 0; //Code on third frame var xspeed:Number = ((_root._xmouse-this._x)*physics0)+(xspeed*physics1); var yspeed:Number = ((_root._ymouse-this._y)*physics0)+(yspeed*physics1); // add the speed to the current position of the object _x += xspeed; _y += yspeed; gotoAndPlay(2); I'm wondering why that would be so when the value for the _xspeed is defined in frame 2. It seems that AS 2.0 is necessary for the code to work whether I publish for Flash Player 6 or 7.
Andy Buchan Date: 26/07/2007
If you want to do this on a rollOver. Running at 30fps it works really well. How elastic this mouse follower is can be adjusted through the elasticity var. make sure you set the linkage on your follower correctly in the library. //if you want to do it all on a rollOver mc1.onRollOver = function(){ var elasticity:Number = 3; attachMovie("follower", "follower", this.getNextHighestDepth()); follower._x = _root._xmouse; follower._y = _root._ymouse; Mouse.hide() follower.onEnterFrame = function(){ seekX = _root._xmouse; seekY = _root._ymouse; follower._x += (seekX-follower._x)/elasticity; follower._y += (seekY-follower._y)/elasticity; } } mc1.onRollOut = function(){ Mouse.show(); follower.removeMovieClip(); } stop();
Bartek Smykowsky Date: 27/11/2009
I currently launched it and I'm gratefull you made it, cause it simpliefied my work at my work a little. Ave oooh Greatest of the Greatest!! :)))
Darren Date: 05/05/2012
<h1>THANK YOU SO MUCH</h1>
Add comment
Home