If physics process is fixed 60 fps, can I use an integer variable being increased 1 by 1 to measure at what part of the 60 frames we are. If _physics_process is fixed 60 fps can I do something like this.

var time=0
_physics_process(_delta):
    time+=1
    if(time==60):
          print("1 second elapsed")
          time=0
  • xyz replied to this.

    Xtreme_93 Sure if you can guarantee that the system ticks at 60 fps. However it'd be better to accumulate delta. That way you account for minor imprecisions in frame duration as well as possible frame drops.

    time += delta
    if(time >= 60.0):
         print("1 second elapsed")
         time = 0

    not sure why you'd do that. First of all, the delta in the _physics_process(delta): should give you a floating point value of time, a delta time if you will, of how long it took for that physics tick to process. You'd rather want to do a time += delta there instead. Second of all, unless you are looking to count the processing time as mentioned previously but instead actual time passed then godot has other utilities for dealing with time.

    https://docs.godotengine.org/en/4.0/classes/class_time.html
    https://docs.godotengine.org/en/3.6/classes/class_time.html
    or if godot 3.x then some relevant methods in OS class as well:
    https://docs.godotengine.org/en/3.6/classes/class_os.html

    edit: got sniped while I went to get my lunch from the kitchen. Ah well.