Hi everyone! I'm a hobbyist programmer and I'm trying to wrap my head around handling time-dependent events in game development. My confusion lies in whether I need to create a separate counter for each entity in the game. For instance, if I want the animations for various characters or objects to run smoothly, I usually maintain an 'action-animation counter' that increments with each progress of the game loop. However, this means that every entity with different animation frame times requires its own counter.
Alternatively, I've implemented a general counter that cycles from 0 to 100 with an Update method, allowing NPC frames to be based on that. While this works, it can be tricky because animations might not always start at the beginning; they could begin from any point in the cycle, sometimes leading to a jump in frames.
Another example is when a character throws a grenade—it needs to explode after a set amount of time (e.g., 3 seconds). Does that mean the grenade also needs its own counter that increments with each Update? I'd really appreciate any advice or suggestions on the best practices for this. Thanks!
1 Answer
Instead of using separate counters for each object, a better approach is to track elapsed time (deltaTime) for each entity or set a future timestamp and compare it against a single global clock. This method simplifies your code and avoids having multiple counters to manage.

I see your point, but with this method, each object still requires some kind of time marking to track when an action starts, right? Like for the grenade, you’d still update a 'detonateTime' field that checks against the global time during each Update, meaning each grenade would still need to check its own future timestamp.