It's indeed a setInterval problem, as the interval and
mouse movement won't necessarily match up.

onMouseMove can also be a problem, as you'll wind up
with a lot of readings going straight
up/down/right/left, rather than in the direction
you're moving.

What I've done for this problem is to average the
mouse movement over 5 or so updates to get a more
accurate reading. Demo here:

http://www.yourmomsa.com/springexp/springexp2.swf

Pick the guy up by the wheel to toss him.


--- "eric e. dolecki" <[EMAIL PROTECTED]> wrote:

> I am calculating mouse velocity, but every now and
> then you get a 0 for
> velocity eventhough its not 0 (setInterval prob I
> suspect).  Any better
> approach?
> 
> var MouseX;
> var MouseY;
> 
> function determineVelocity():Void
> {
>     MouseX = _root._xmouse
>     MouseY = _root._ymouse
>     setTimeout( calc, 9 );
> };
> 
> setInterval( determineVelocity, 20 );
> 
> function calc():Void
> {
>     var newMouseX:Number = _root._xmouse;
>     var newMouseY:Number = _root._ymouse;
> 
>     var deltaX = Math.abs(MouseX - newMouseX)
>     deltaY = Math.abs(MouseY - newMouseY)
>     dist = Math.sqrt((deltaX * deltaX) + (deltaY *
> deltaY))
>     velocity = dist*31; // 31 = fps
>     trace( velocity );
> };
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the
> archive:
>
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 



       
____________________________________________________________________________________
Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 
http://tv.yahoo.com/collections/222
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to