Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to make a 2D Platform game and so far I can have my character moving around in a tiled map and collisions are working too. So far so good.

The problem I'm having is that the character can get "unaligned" with the map if I spawn it without double checking the X coordinate. This means that, on certain conditions, the character could walk over a small gap (just large enough for it to fit in) on the floor. This happens because the X speed is a constant value, so in one frame the character is standing before the gap but the next frame it's past the gap.

I can solve it by simply making sure the spawning coordinates will be aligned with the map (and the X speed allows it since the tile size is a multiple of it), but it does sound like a fishy solution to me since I may want to add power-ups in the future that increase the speed.

So I'm wondering if I'm missing something on how characters should move or maybe I should actually just double check the spawning coordinates? Or maybe it is a normal thing to happen in a game??

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If the "fixed speed" is a feature of the game (e.g. so that in a tile based game the character is always positioned in line with the tiles), you need to ensure that X is initialised to a good initial step.

If not then you have a couple of options

  1. The simplest change that you could do would be to make the "fixed speed" small enough relative to other dimensions in the game so that issues like this aren't a problem (e.g. make the gap bigger)
  2. A more sophisticated solution would be to work out the distance travelled each frame based on the characters speed and the elapsed time since the last frame. This would mean that the distance travelled over time would be constant howeve the distance travelled each frame wouldn't. Consider reading Fix Your Timestep!.

With option #2 you would still need to ensure that your gap is big enough so that the player can fall down without too much difficulty.

share|improve this answer
    
I think I might keep the fixed speed for this game. While the second option sounds like a good plan, it seems the game would run slightly different every time due the speed being almost "constant". Though the 'Fix your timestep!' link was very helpful and I might use the second option for a different kind of game later, thanks! –  aslg Jun 2 '13 at 9:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.