How do I create movement with deta time?

0 favourites
  • 3 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • Hi everyone, hope you are doing well today.

    I'm currently working on my mobile video game on C3. It's a top down game where you need to dash to move and attack ennemies.

    Dashing is made by pressing the screen, dragging and releasing. The more you drag, the more power you put in your dash.

    I decided to code it from scratch rather than use a C3 behavior.

    But when I've tested my game on a mobile phone, I discovered that my dash movement wasn't consistent (with the same power, I ran more distance on mobile than I do on PC).

    I made some research and found out about delta time to control my movement independently from FPS.

    But I have a really hard time understand how I should transpose the delta time workflow with my actual code.

    That's why I need your help here.

    I've recorded the gameplay so you can better see how it works.

    Here's also a screenshot of the code of my actual movement.

    youtube.com/shorts/NVLijoig0C8

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here’s a few ideas:

    Speed up

    Speed = speed + acceleration*dt

    Slow down

    Speed = speed - deceleration*dt

    Also speed*0.5 is the same as lerp(speed, 0, 0.5)

    So supposedly the way to make that use dt is lerp(speed, 0, 1-0.5*dt) but you’d probably have to tweak the 0.5 value.

    So you’d utilize that idea whenever you’re using a scaled value of speed.

    That should mostly make things consistent. It will still vary a bit at different frame rates though. Sometimes you can throw more math at it in some cases to improve it. Easiest way to make completely deterministic physics is to run at a fixed frame rate but construct doesn’t provide a way to do that.

  • Hey R0J0hound ! Thank you very much for your reply. I think I've managed to get it right.

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