What is the best way to do fall damage?

0 favourites
  • 9 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • Hello again,

    I want to add fall damage in my game. I want it to be similar to Terraria's fall damage system

    How would be the best way to figure out how many blocks the player has fallen (like Terraria, the blocks are 8x8 pixels)? Should I use timers or should I make it when the player first starts to fall store his Y value, and then when he lands calculate the difference between the fist Y value and his current Y value and divide them by 8? Is this a good method or should I do something else?

    Thanks,

    Give me a Pixel

  • the first thing that pops to mind is to give every tile an instance variable called "level" or something. bottom would be zero, higher blocks would get 1, 2, 3, etc depending on their height.

    Als your player collides with a tile, keep track of the current level as an instance variable of the player, and whenever you collide with a tile with a different level as the player has at that time, and the tile is lower, then subtract them to know how many levels he dropped

    just a suggestion, maybe there are faster ways

    greets

  • Well, I am using a tilemap, not individual sprites. And that way seems more tedious than the comparisons of Y values I mentioned earlier. I am probably not going to use that, but thanks anyway.

  • bump.

  • savvito123

    That looks like it would work, however the problem is that the damage needs to be calculated by the number of blocks fallen, not the time in the air. That is probably not what I'm looking for either, but thanks anyway. Sorry if I'm being too picky.

  • You can calculate the time your player need to fall for one block and change the time to that one.

    Another way is to store a variable startY on player fall and another variable endY on player landed and calculate the distance between them.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, the latter is what I was planning on doing unless someone could come up with a better way, see my first post.

  • Agreed StartY and EndY would be the best way to handle this, imo. You don't want to tie it to time in case of physics engine or framerate variation. Also consider whether you want to set StartY when the player leaves the upper platform, or at the apex of whatever height the player starts actually falling from, in case the player jumps off the platform vs walks off.

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