0
\$\begingroup\$

I'm trying to build a game from scratch in Dart, similar to Minecraft.

As far as I understood, there are two main functions in a general game loop:

  • tick: a function that gets executed a fixed amount of times per second independently of the framerate. And I think in Minecraft those are called TPS (Tick per second).

  • render: a function that draws everything on the screen, called every frame, the frequency of which depends on the device's capabilities. (FPS)

(I am referencing Minecraft as it's a well-known game and it's quite simple)

What I'm trying to understand is at which time should collisions be checked for? Are they checked each time the screen draws (render) or every time the tick function runs?

\$\endgroup\$
1
\$\begingroup\$

Collisions are part of the physics update, which is typically handled in the fixed timestep loop (what you call "tick" here).

By handling collision detection and resolution at a fixed game time interval, you help ensure that the physics play out consistently even on very different hardware.

If you do physics on a variable timestep (like in the render loop), then folks running at a low framerate can get glitchier physics — objects have to move further in each physics step to keep up the right apparent movement rates, so they're prone to tunneling through collisions that would have been caught and handled correctly if using smaller steps.

In the Unity game engine as an example, this fixed timestep defaults to 0.02 seconds, or 50 Hz. Other games use different values, so you can tune it to get the right balance between performance and physics precision for your game.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.