Skip to main content
5 votes

Finding average input value over time in seconds

Expanding on Stormwind's lead, I'd be curious whether your application needs a windowed average with equal weights per unit of time, or if an exponential moving average may suffice. The latter is very ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Score over time

You can do this with a timer like this: In your Create event (or where you want to start your counting): alarm[0] = 1; Then in your Alarm 0 event: ...
Jeggy's user avatar
  • 166
5 votes

I want to delay 3 sec to load next level after the collision in C#

You are destroying the GameObject on which this script is running as soon as it collides with an enemy. (Destroy (gameObject);) That means it can't wait 3 seconds ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

How do I blink a sprite a few times before it disappears?

It appears you want Blink to be executed as a coroutine. But you are executing it directly. If you call an IEnumerator method directly, you receive an ...
Philipp's user avatar
  • 120k
4 votes
Accepted

Is Time.deltaTime different on various devices?

On some platforms the game actually starts running before the splash screen is gone. So this may give the illusion of a defective timer if you test it right at the start. Another issue on slow ...
Stephane Hockenhull's user avatar
4 votes
Accepted

Saving total play time could be fine?

Floating point precision is unlikely to be the problem here. Since you're not trying to coordinate simultaneous use, but just determine which of two sequential sessions came earlier/later, you'll ...
DMGregory's user avatar
  • 135k
3 votes

synchronizing client-server actions

The short of it is that your game design and art both need to be built around the realities of networked play. When the user clicks, they should not immediately attack. Instead, the animation/effects ...
Sean Middleditch's user avatar
3 votes

How to structure a game that continue even when closed?

The proper way to do this is, when you exit the game, save the current time somewhere in your project. My .Net skills are awful, but a quick google search suggests ...
Tom Tsagkatos's user avatar
3 votes

Time based events separate from the game loop

Time elapsed events are not separate from the game loop but are controlled from the game loop. The easiest way to achieve the effect is to have a floating-point value that represents the number of ...
Casey's user avatar
  • 2,045
3 votes
Accepted

Time based events separate from the game loop

This is a very wide question, and difficult to answer specifically, so I will be general instead: Any "over time" effects will still be based on your game loop, but have their own "tick" of time they ...
Ian Young's user avatar
  • 2,649
3 votes

Timer as part of a condition

Myself, I'd recommend separating the jobs of reading from the sensor, running your timer, and coordinating your scene transitions. This way each script can do one simple job, so you don't end up with ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Timer breaks after changing scenes

Time.time returns the number of seconds since the start of the game. "Start of the game" refers to the moment the game was launched, not the moment the current ...
Alex Myers's user avatar
3 votes

How do I blink a sprite a few times before it disappears?

When you call Blink you are discarding its return value: Blink(itemClone); You do not want to do that. I believe you want to ...
Theraot's user avatar
  • 27.2k
3 votes
Accepted

Phaser 3 - How to trigger an event every 1 second?

In your scene's update method you receive both the current timestamp, and the delta since the last update call (see https://photonstorm.github.io/phaser3-docs/Phaser.Scene.html#update__anchor) You ...
vassildador's user avatar
2 votes

In Unity, how do I set up a delay before an action?

Multiple choices, but you will have to use Coroutine sometimes, so try to figure out why its not working here. My tips : careful to not call StartCoroutine in Update() without protection. Exemple: ...
Waxim Corp's user avatar
2 votes

I need my timer to go up every 30 seconds

Ultimately, there are several ways to do this. WaitForSeconds can be used inside a Co-routine, but I would recommend simply keeping your own count, or using ...
Gnemlock's user avatar
  • 5,273
2 votes
Accepted

Finding average input value over time in seconds

Two options: 1. Arithmetic average (worse) Have a 2-column table that has sufficiently many rows to be able to store all values for your chosen time (0.1 s in your question) at the potentially ...
Stormwind's user avatar
  • 1,063
2 votes

SDL - Limiting loop with timer? Not polling

SDL_AddTimer is a problem here. SDL_AddTimer spawns a new thread, and things won't work like you expect when using multiple threads. When you call SDL_Init(), you likely do it from the main thread, ...
prushik's user avatar
  • 186
2 votes

Making quick time events in my text adventure more noticable

I'm not familiar with Unity's text-adventure capabilities--is there a technical reason not to just use text for this, by adding an additional message every N seconds until they act or time runs out? ...
abathur's user avatar
  • 283
2 votes
Accepted

Making quick time events in my text adventure more noticable

There is really just one real solution to this conundrum: Playtest it! If players complain about not noticing they were making a decision under time-pressure, you need to find a solution. When they ...
Philipp's user avatar
  • 120k
2 votes

How to cause delay of 1 second of bullets when space pressed

What you can simply do is keeping the last bullet launched time, and when trying to fire check if the ellapsed time is over 1 second to launch the next bullet. It could look like this ...
realUser404's user avatar
  • 1,057
2 votes
Accepted

How to kill a fired bullet sprite after certain amount of time in Phaser?

I found out that objects can be killed with body.lifespan Adding the line bullet.lifespan = 1000; in my ...
flufflepuff's user avatar
2 votes

Make timer for game to run for 2min

If you record the time once at the start of your game: time_t startTimeSeconds = time(NULL); // must include 'ctime' Every update (game loop iteration) you can ...
Quintin Steiner's user avatar
2 votes

Game time and pausing

My favorite way to pause a game is this: ...
Tom Tsagkatos's user avatar
2 votes
Accepted

Keep the timer counting after changing scenes

You can just put the line in the Unity API of DontDestroyOnLoad() inside Awake() method and your object will not get destroyed ...
John Hamilton's user avatar
2 votes
Accepted

To implement a game object that expires, should I store the start time and total, or store the remaining time?

There is no "best" way to do this, both methods are completely viable and personal preference. However I believe that the delta time version is superior because it's inherently less error-prone than ...
Charanor's user avatar
  • 7,870
2 votes
Accepted

Unity3d Pause RigidBody object, don't stop time

Turn off auto physics simulation: https://docs.unity3d.com/ScriptReference/Physics-autoSimulation.html Or if you happen to be doing 2D: https://docs.unity3d.com/ScriptReference/Physics2D-...
Ed Marty's user avatar
  • 5,229
2 votes

Use vsync event instead of a 16ms timer?

There are various reasons not to use the vsync event nowadays. Indeed, historically when the games had to sync with the refreshrate of the screen because the ‘redraw’ would be visible or cause a ...
Felsir's user avatar
  • 4,067
2 votes

Multiple events based on in-game timer?

You're overthinking this. Polling the in-game time each frame is nothing compared to the other things your CPU does each frame. You would need millions upon millions of entities to see the a ...
Charanor's user avatar
  • 7,870
2 votes

Multiple events based on in-game timer?

You can also have a master "Schedule" that acts as a priority queue. This automatically sorts the next item to occur so that it's the first item in the collection (often more cheaply than ...
DMGregory's user avatar
  • 135k

Only top scored, non community-wiki answers of a minimum length are eligible