How do I detect acceleration in touch?

0 favourites
  • 5 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • I am trying to change the animation of my sprite to its "Run" animations based off of the acceleration of the touch on both the x or y axis.

    Currently the sprite plays its "walk" animation for the respective directions just by being in touch.

    I want the sprite to "Run" if the touch is being dragged faster across the screen.

    I'm sure the answer is quite obvious but I don't know the math behind it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Touch.SpeedAt(0) will give you the current speed. But if you need to detect acceleration, you will have to measure the speed over some time.

    For example, you can compare the current speed with the speed in the previous tick. Add the difference (positive or negative) to a variable. After 0.5 seconds, if the variable contains a positive number, then the touch is accelerating.

  • What would the code look like to compare the Touch.SpeedAt(0) with the speed after the tick? Do I need assign two variables to each speed then use the "Compare Two Values" line?

  • Save the speed from a previous tick in a variable, for example:

  • Save the speed from a previous tick in a variable, for example:

    Thank you this makes sense

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)