TimeDelta confusion

This forum is currently in read-only mode.
  • http://www.sendspace.com/file/9wsxos

    This is the custom platformer movement that I'm working on. I know, I should just use the built in one, but it's all over the place right now. I'll switch back over in the next version assuming everything gets fixed. It's good experience for me though, this stuff will be useful in other situations.

    Anyway, I've read about how I should use TimeDelta and after running this at a low framerate, I see why.

    Problem is, I have no idea how to inject it into this context. Partially because I still don't really understand what it's doing.

    So if someone could take a look at it and let me know how to get the movement to be the same rate over time at different framerates, that would be a big help. Any advice on how I should change this would be great, really.

    I didn't make any comments in it, unfortunately. Ask away if you have questions.

    By the way, the reason I added the built-in platformer behavior to the player is because even without controlling movement with it, it works wonders for collisions with moving objects. I wouldn't know where to begin putting that stuff in on my own.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Using timedelta isn't all that hard once you get used to it. If your FPS target is 60 then this:

    Sprite: Set X to X + (100*timedelta)
    [/code:28zr4w5q]
    
    will move your sprite at a rate of 100px per second to the right, and this:
    
    [code:28zr4w5q]
    Sprite: Rotate 180*timedelta
    [/code:28zr4w5q]
    
    will turn your sprite around a half turn every second.  Basically timedelta is the time between the last tick and the current tick, which changes from tick to tick because rendering time fluctuates.  Over the course of one second, all the deltas should average out to a total of 1 (1 / 60 = 0.0166... seconds which is the average time between ticks).  So if you're moving something at 100px*timedelta, then in one tick it will move on average about 1.6 pixels.
    
    There's a good amount of info on timedelta on the wiki, you should check it out.
  • The problem is that when I move the sprite 60*timedelta pixels or whatever, it's moving at fractions of pixels, which screws up my collision detection. In my current thing, if you're stuck in a wall, you'll be moved out by 1 pixel until you're out. But if you were 2.47 pixels into the wall or something, you'd be moved out 3. This means that falling down a hole the size of the player is pretty much impossible, because your pixels aren't lined up exactly. And it won't know to move you out exactly 2.47 pixels, because that just happened to be the time between ticks at the time of entering the wall, it might be different by the time it's detected. I tried rounding the number, and though that happened to work at 60 fps, you always stop one pixel away from walls at 20 or 30 fps. And you seem to move more quickly at 20 fps than at 30, so I'm clearly doing something else wrong anyway.

    Ugh, screw it, doing this is going to be so much more work than it's worth. I don't want to have to figure out if the player teleported through any walls due to a low framerate either. The game wouldn't be fun in chop-o-vision of any kind anyway.

    I guess this means I can't use any built-in behaviors, because they all use timedelta, right? Pretty annoying.

  • They're timedelta-compatible. They still work in fixed FPS I'm sure (never used them).

    As for making a movement with timedelta, you're probably giving up before trying all solutions. You could do things like force sprites out of walls they're touching in a loop, or move the character more incrementally in loops than you're currently doing. But a side-effect of timedelta IS that it's not precise, but you can make most things work just fine.

  • I guess this means I can't use any built-in behaviors, because they all use timedelta, right? Pretty annoying.

    Well if you don't like timedelta then yeah, I guess so. Hope you don't mind if I still use them.

    Good luck with your game.

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