Smoother Touchscreen Drag Movement?

0 favourites
  • 5 posts
From the Asset Store
Use inertion of your movements to throw, rotate your objects and etc. Objects can interact with others while dragging.g
  • Hi,

    For a game, I'm using the Touch object to move a character. I want its movement to match the finger's direction dragged across the screen.

    The two solutions I've tested so far are:

    1)'Move At Angle' action with Touch.SpeedAt() * dt and Touch.AngleAt()

    2) Bullet behavior with angle of motion set to Touch.AngleAt and speed at Touch.SpeedAt

    Both solutions work, but the movement is often stuttery and doesn't exactly match the finger's drag: Sometimes it flies farther than I wanted it to, sometimes the movement has pauses on frames, etc. I thought it might be a performance issue, but the game is running fine at 60fps - no interruptions across any platforms I've tested on.

    Is there something I'm doing wrong? Or a different method I can use?

  • Touch speed may be very inconsistent. One tick it's 50 and another tick it's 5000. You should probably limit the maximum speed - min(Touch.SpeedAt(0), 1000)

    You can also try smoothing it with lerp.

    Variable charSpeed
    
    On every tick : Set charSpeed to lerp(charSpeed, min(Touch.SpeedAt(0), 1000), 0.3)
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The lerp solution worked, thank you! Though now the movement feels like it has a bit of lag, like it has to take a moment to accelerate upwards to the finger's speed.

  • You can increase the last parameter in lerp to 0.5-0.6 for sharper movement.

  • Changing the value made it work exactly how I needed it, tysm! 👏

    I haven't used Lerp before. I'm out of touch with programming math and have a lot to learn lol

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