Advertisement Jump to content
Sign in to follow this  
MarkusH82

Speeding up a game question

This topic is 1817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I am currently developing a simple Tower Defense game and would like to implement the functionality for the player to speed up the game.

 

First, I was thinking it is easy to solve by speeding up the the enemies and towers, but a simple equation showed me it is not that easy.

 

For example my enemy is standing at x=0m its speed is 10m/s and the time per frame is 1s (to make the calculation easier).

 

So after one frame my enemy is at x=10m   (pos = speed * time)

 

To double the game speed I would double the enemy speed, and would get the enemy position at x=20m after one frame.

 

Now, if I have a tower at x=10m with a range of 5m in both directions, then the enemy in normal speed would be in range. The enemy with double speed would not be in range. So, this shows me that just increasing the speed is not the solution for a time based game.

 

Does anybody has experience with that and could help me?

 

Best regards,

 

Markus

Edited by MarkusH82

Share this post


Link to post
Share on other sites
Advertisement

I was also thinking about making the game framerate based, but is there not also a solution for time based games? Is a fixed timestep not a problem if one computer runs faster then another?

Share this post


Link to post
Share on other sites

I was also thinking about making the game framerate based, but is there not also a solution for time based games?

 

not a good one since it won't be deterministic. you can multiply the elapsed time by x to speed everything up but it will change the simulation. (Fixed timestep does not mean that the framerate is fixed, only that you update the game state at a fixed rate)

Share this post


Link to post
Share on other sites

The solution to this varies greatly depending on your implementation details. If you're using a grid, you can just force units through every square/hex of the grid even if they're moving 2 squares in one unit of time. This assumes you trigger from that in some way, shape, or form. If you're using geometric shapes and effectively no grid, you'd check for intersection between the line segment of the unit's movement and range of the tower. How long the tower fires (how much damage it does) needs to be calculated, but your existing code for that should require minimal changes to handle whatever solution you choose.

 

I have to ask, are you really writing a tower defense game where units move so fast that they pass an entire tower's range within 1 frame (~16ms at 60fps)? I cannot fathom a game where I'm expected to see action that fast. Usually, you cap the speedup a player can use well, well, well below that point.

Share this post


Link to post
Share on other sites

@SimonForsman: Thanks for that article, just finished reading it. I will try the last solution with a fixed time step.

 

@richardurich: Of course no enemy will be fast enough to skip a tower range. My calculation was really just an extreme example, but it shows that even if the time per frame is small enough the gameresults can variate with different speed values. This is maybe just a small difference, but I would like to avoid it.

Edited by MarkusH82

Share this post


Link to post
Share on other sites

If you could grab the delta time between frames and multiply that by 2, it would give you a 2x speed. I guess it does depend on how your code structure is setup though

Share this post


Link to post
Share on other sites
@emcconnell: it's still the same problem. Doubling the delta time is the same effect then doubling the speed.

@Spiro: I don't think I did a poor job in describing my problem. It is simple math. And yes you are wrong. If I double the speed and the enemy skips the tower range within one frame then even doubling the bullet speed doesn't help, if there is no collision.

Anyway, I reached my goal with the article that Simon recommented.

Share this post


Link to post
Share on other sites

Anyway, I reached my goal with the article that Simon recommented.

It is impossible to say that I was wrong and that you reached your goal with that article.  These are mutually exclusive statements.

 

If you believe you have reached your goal with that article, you have a fundamental misunderstanding of the problem and the math behind it.  You just confirmed that by stating that doubling enemy speed has anything to do with frame counts.  What does a “frame” mean to a game?  What length of time is that?

16 milliseconds?  2 minutes?  32.3 days?

 

Of course you need a fixed time-step.  That’s true for anything you make.  That link alone is not the answer to your problem in itself.  It’s about how you speed up and slow down the game and how you manipulate the fixed time-step.  Read my reply again until it makes sense.

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!