Search code examples
game-physicsgodot

Godot - Get physics fps from script?


So I want to set a speed in pixels per second and then calculate how much to move that specific physics frame. something like const speed = 500 / get_physics_fps(), I could in fact just do:

func _physics_process(delta):
    var speed = 500 * delta

but it feels like kind of a waste to calculate every frame something we know isn't going to change, also I can just divide by 60 or whatever I set my physics fps to, but that would be kind of harder to mantain than it needs to be.


Solution

  • You can retrieve the physics FPS from ProjectSettings:

    var fps = ProjectSettings.get_setting("physics/common/physics_fps")
    

    However, it is extremely common to calculate translation by multiplying speed by delta in _physics_process. Choosing some unusual alternative is just going to make your project more confusing, and is only worthwhile if you've already identified a performance bottleneck directly related to this. If you haven't, you're falling into the premature optimization trap, wasting time and headspace optimizing things that don't matter, meaning you won't have time to optimize the things that do matter later.