Organic Mouse Interaction in Actionscript
26 May 2008
I am porting this article and its 2nd part over from my old blog of an early experimental concept of how the classic easing+mouse-following movieclip can be made more organic (code is in AS2).
What’s a mouse-following movieclip? You can find examples of mouse-following movieclips at the Haze website I did and this Kirupa tutorial. Below is an example I did.
Wouldn’t it be better if the motion of the ball be controllable by the speed of the mouse movement? If you move the mouse faster, the ball catches up faster and vice versa. Have a look at the second example which accomplish just that.
You can feel that the movement of the ball has more character now, even though the movement isn’t exactly polished. The speed of mouse movement is measured in pixels per second.
It really is simple. All I had to do is continuously check the position of the mouse position every e.g. 100 milliseconds and get the position of the mouse now and 100ms prior. With the 2 positions I can get distance and then speed. The resulting speed is then used for the easing speed of the ball.
Next I’ll add another factor—mouse angle. Usually mouse angle is calculated with the current mouse position and an “origin”. In this demonstration, both the mouse position and origin are dynamic but are easily checked with the same update functions that check mouse speed. The end point would be the current and origin would be 50ms ago (configurable tracking speed). With basic trigonometry we get radians which are then converted into angles.
By varying mouse speed and detecting mouse angle, you get interaction that is more organic and natural. If you have used my code in a project, please let me know by posting a comment!
bUtTerCrACkeR 27 May 2008, 12:41 PM
This is pretty cool. You should come up with an AS3 version.
Peter 05 Aug 2008, 1:51 PM
Where can I download the source? I can’t seem to find it :(
Thanks!
Pete
Aen 05 Aug 2008, 2:24 PM
You can’t see it because the source is not available for download. I’m just showing a proof of concept with this article. I’m building something with it and as I launch I will release its source.
Hmm I did mentioned something about using my code. Guess that was a error on my part! I’ll release it soon enough.