Upbge 0.3 time and delta time

I use that code , but i got different delays each time , it does not seem reliable.
How to get time since game start, and how to get engine deltaTime to get game logic working at constant frame rate not depending on game speed ?

    delta = time.process_time() - owner["timeGameOver"] 
    if delta > 3 :  
        owner["displayGameOver"] = True

Firstly, if you are applying velocity rather than moving the objects location, then it should go the same speed regardless of framerate.

To get the time between each frame, I’d do something like this:

import bge
import time

currentTime = time.time()
delta = currentTime - bge.logic.theTime
bge.logic.theTime = currentTime

“delta” will be the value in seconds between this frame and the last time you ran that script.
Note that you’ll want to initialise bge.logic.theTime somewhere before doing that.

As for finding out the time since the start of the game, first you need to remember the time that the game started:

bge.logic.gameStart = time.time()

Then, this will check if you are 30 seconds since the start of the game:

if time.time() - bge.logic.gameStart > 30:
   print("30 seconds have passed")
1 Like

Thanks you.
It looks like it’s not consistent using time.time(), i got sometimes positive delta values sometimes negative values.

currentTime =   time.time()
print("time current : ", currentTime)

if owner["pHealthMin"] == True and owner["displayGameOver"] == False:     
    if owner["timeGameOver"] == -1 :    
        owner["timeGameOver"] = time.time()
    delta = currentTime- owner["timeGameOver"]  
    print("delta : ", delta)
    if delta > 2 :  
        owner["displayGameOver"] = True