Invoke & framerate

Hi,
I’m new to Unity. In my game, I’m using several Invoke’s as a timer for certain events.
The docs state:
Invoke("LaunchProjectile", 2);will launch the projectile after 2 seconds.

But I’ve read that Invoke is frame rate dependent. So, let’s say the game is running on one pc at 60fps, and another 120fps. The projectile will take twice as long to launch on 60fps, right?

So… at what framerate does the projectile take exactly 2 seconds to launch? 30fps? 60fps? Something else?

It’s always as close to 2 seconds as is possible given the framerate. It’ll be more accurate (closer to two seconds) at 120 FPS than at 60 or 30. It always invokes after the time has elapsed and never before.

It basically checks every frame “has this time elapsed?” if so then it invokes, otherwise it waits.

1 Like

I see, that makes sense. Thanks for the info.

While we’re at it:
I want a score to be calculated as the time elapsed in milliseconde. Using InvokeRepeating(…,0,0.001) doesn’t seem to work. It’s not able to keep up in milliseconds, it’s rather 0.01 seconde or less. How would I do this?

You can hard cap frames per second. So that each machine run it at 60 (I would not go for less unless You want to piss off PC crowd). Think of it like hard coded vsync. Unless someone have a high refresh rate monitor noone will probably notice.

Yeah, don’t do this unless you have a good reason to (you probably don’t) :slight_smile:

So you want to count time in order to calculate a score? Just use Update and add Time.deltaTime to a cumulative float value.

OK, thanks for the suggestion!