How to detect drag speed?

creativeappscreativeapps Member Posts: 1,770
edited February 2013 in Working with GS (Mac)
How do I detect drag right to left counts. For example If I drag slowley its display low counts if I drag fast its display higher counts. Is there any demo sample for that?

Comments

  • creativeappscreativeapps Member Posts: 1,770
    @RP Thanks
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Speed = distance/time

    To get the speed of the mouse.x (for instance) at the fastest frame-rate of the device you could make three (real) attributes 'currentSpeed', 'oldTime' and 'oldMouseX" then use the following three constrain behaviors:

    Constrain Attribute [self.currentSpeed] To: [( game.Mouse.Position.X - self.oldMouseX )/( self.Time - self.oldTime )]
    Constrain Attribute [self.oldTime] To: [self.Time]
    Constrain Attribute [self.oldMouseX] To: [game.Mouse.Position.X]

    There is just (barely) enough processing time between iterations so the time value is different (about a 60th of a second at the fastest).
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    I've been messing with this idea a bit more and realized that @ericzingeler's low pass filter would work nicely to smooth out the swipe speed. Here is a way to do it that is fiendishly accurate!

    When mouse button is down
    -- Timer - every 0 seconds
    ---- Change Attribute: [self.SwipeSpeed] To [( self.SwipeSpeed *.96)+(( game.Mouse.Position.X - self.oldX )/( self.Time - self.oldTime )*.04)]
    ---- Change Attribute [self.oldTime] To: [self.Time]
    ---- Change Attribute [self.oldMouseX] To: [game.Mouse.Position.X]
  • creativeappscreativeapps Member Posts: 1,770
    @RThurman Thanks Do you think that gs can detect full speed accurately?
  • SocksSocks London, UK.Member Posts: 12,822
    I've been messing with this idea a bit more and realized that @ericzingeler's low pass filter would work nicely to smooth out the swipe speed. Here is a way to do it that is fiendishly accurate!

    When mouse button is down
    -- Timer - every 0 seconds
    ---- Change Attribute: [self.SwipeSpeed] To [( self.SwipeSpeed *.96)+(( game.Mouse.Position.X - self.oldX )/( self.Time - self.oldTime )*.04)]
    ---- Change Attribute [self.oldTime] To: [self.Time]
    ---- Change Attribute [self.oldMouseX] To: [game.Mouse.Position.X]
    @RThurman

    Just spotted this, really good stuff !
Sign In or Register to comment.