16
\$\begingroup\$

How can I implement the fast forward feature for my tower defense game like in http://fieldrunners.com/ and other TD games?

I am using Unity 3D. Would there be something to manage fewer frames per second or some kind of manually set fast movement of enemies and tower firing speed, et cetera?

\$\endgroup\$
1
  • \$\begingroup\$ have you tried to increase the update frequency ?? you may need to skip frames.. \$\endgroup\$
    – concept3d
    Commented Dec 20, 2011 at 14:20

3 Answers 3

7
\$\begingroup\$

if your game doesn't have complicated or computationally expensive simulations that require separating them into independent update timelines, you can use a simple approach of basing the code in your Update() functions on Unity's Time.time value, and in your code set the value of Time.timeScale to be whatever you want. 0 == paused, 1 = normal, our testers love to set timeScale > 1 to get things done faster.

http://unity3d.com/support/documentation/ScriptReference/Time-timeScale.html

\$\endgroup\$
19
\$\begingroup\$

Approach: Higher simulation rate

Your timing for your user interface should be decoupled from your actual game loop, as should your rendering. Say for example your world runs at 4x speed. Lets say that at your basic (1x) speed, your game runs 30 updates per second.

You would then have something like the following, when in fast-forward mode:

  • World logic runs 4 updates for every update of UI and renderer. This means it needs to run 120 updates per second. Thus, your world model (data) is updated at this rate.
  • Renderer and UI logic both continue to poll or do whatever at 30 updates per second.

In other words, the game as a whole is not running faster. The simulation part is.

You can deduce two things from this:

  1. You need to keep your game logic simple enough that you can easily run it four times faster on your target platform, OR you need to introduce methods to extrapolate various aspects of gameplay more quickly -- this can result, though, in a model that is different from what it would have been if you had simply used a more rapidly paced simulation. So the tradeoff would be processing cost for accuracy. See approach 2, below.

  2. It is the separation of concerns that allows you to easily speed up your world simulation, that separation being model, view and controller (MVC). If your world data(M), render logic(V), and game logic(C) are all mixed up, you really won't be able to do this, at least not without a massive migraine.

Approach: Extrapolation based on time deltas

As mentioned above, you'll need to calculate motion based on how far something would have travelled in a given time. This assumes your game physics are inherently more realistic in their simulation, however, which may not be the case. This is a rather larger topic and considerably more complex. You'll need to ask more questions about if you want to know. Essentially, you'll be doing some calculus to get things right. You'll need to deal with interpenetration in collisions and a host of other issues I won't go into here.

To conclude

This gives you the general outline. Your language choice is your own, presumably you either know how to do that in Unity or you don't. Timing in any language requires you to understand the ins and outs in detail, I'd suggest starting with Gaffer's articles and checking out the Unity API docs.

\$\endgroup\$
1
  • \$\begingroup\$ If you are going to use the higher simulation rate approach, and you want to support slowdown, you probably need to actually have an extremely slow base simulation rate, then run that by default at like 100 simulation steps/frame. \$\endgroup\$
    – bobobobo
    Commented Nov 18, 2013 at 18:06
9
\$\begingroup\$

As a general principle, the update of game logic should be decoupled from the update of the game's graphics -- that is, simulation of your gameplay, AI, unit movement, et cetera should not be tied to the speed at which the game is rendering. Usually the main game loop computes how much real time had elapsed since the last game update, and sends that delta time step to the update routines of each individual game logic object.

In such a scenario, it becomes simple to implement time scaling (including fast-forwarding) in your game. Simply premultiply the game logic time step by some scalar value that controls how much to "fast-foward" or slow down time. By default this value would be one, and for example once the user hits the "fast forward" key you set it to 1.5, and all simulation would appear to go 50% faster. You would still render at the same rate, however.

I am not extremely familiar with Unity and thus could be wrong in the following suggestion, but Unity does have a time management component which may be useful for implementing this. It in fact already has a timescale property. The description of the component implies that the class was designed for physics objects, but it may be applicable to your scenario as well.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It is definitely applicable to his scenerio. All he would need to do is set Time.timeScale to some multiplier and everything will just go faster. It's an across the board change, so if there are things like menu interactions and such they'll also go faster, though. \$\endgroup\$
    – Tetrad
    Commented Dec 20, 2011 at 17:20
  • \$\begingroup\$ thnx again Tetrad :) \$\endgroup\$
    – Syed
    Commented Dec 22, 2011 at 10:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .