How do I get the current X speed in pixels per frame?

0 favourites
  • 7 posts
From the Asset Store
Per Pixel Destruction like in "Worms" (perfect performance, no third party plugins)
  • How do I get the current X speed of an object in pixels per frame?

    I can only find the current X speed per second, so I've tried to devide that by "fps" (playerobject.Platform.VectorX/fps), but that didn't seem to work for some reason (I'd really like to know why)

    Does anyone have a solution?

    Thanks,

  • The distance covered per frame is calculated as pixels_per_second * dt, so just divide by dt to get the per-frame pixel step.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks a lot, but it didn't seem to do it.

    This is where I've used it:

    If obj_player is mirrored: for obj_cam - Set X to "lerp(Self.X, obj_player.X-150, (0.006 * 4)) + (obj_player.Platform.VectorX/dt)"

    If obj_player is not mirrored: for obj_cam - Set X to "lerp(Self.X, obj_player.X+150, (0.006 * 4)) + (obj_player.Platform.VectorX/dt)"

  • I've no idea what you're trying to do, but dividing a speed in pixels per second by dt to get pixels per frame is correct.

  • Lerp(a, b, x) is a formula where x is not in pixel per seconds nor pixels per frame, it is a numerical ratio with no units, so dividing it by dt is of no use (using lerp this way is also something I would never ever recommand, no idea why everyone is using it like that).

    If you explain what you are trying to achieve, we might find a better way to do it.

  • Thanks Aphrodite, but I want the camera to focus on the player -150 when the player is facing left and +150 when the player is facing right.

    But the problem is that the camera can't keep up with the speed of the player so I thought that adding the speed of the player would fix that (which it did, when I replaced dt with 60 (because the game ran at around 60 fps)).

    The problem is that the game doesn't always run at 60 fps, so that's not a solution.

  • Bump?

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