0 votes

Hello,
I have recently begun implementing a system into a project where the physics fps will be adjusted to match the monitor refresh rate. To do this vsync is enabled and in the _process() function of an autoloaded script the fps is measured and then the physics framerate is set to it as such:

func _process(_delta: float) -> void:
    var fps = Engine.get_frames_per_second()
    if fps > 60:
        Engine.iterations_per_second = fps

However this is causing an issue where objects that use the delta value of physics process are moving slower at high refresh rates such as 360Hz. Here is the movement code:

func _physics_process(delta: float) -> void: 
    direction.x = int(Input.is_action_pressed("MoveRight")) * Input.get_action_strength("MoveRight") - int(Input.is_action_pressed("MoveLeft")) * Input.get_action_strength("MoveLeft")
    direction.y = int(Input.is_action_pressed("MoveDown")) * Input.get_action_strength("MoveDown") - int(Input.is_action_pressed("MoveUp")) * Input.get_action_strength("MoveUp")
    if direction != Vector2.ZERO:
        velocity = MAXSPEED * direction
    else:
        velocity = Vector2.ZERO
    move_and_slide(velocity * delta)

Surely the decreased delta from the higher physics fps should be balanced out by having more physics frames? How do I fix this?

Godot version 3.2.4 beta 5
in Engine by (12 points)

1 Answer

0 votes
move_and_slide
linear_velocity is the velocity vector (typically meters per second). Unlike in move_and_collide(), you should __not__ multiply it by delta — the physics engine handles applying the velocity

Right now you have delta^2 factor of speed from FPS instead of linear delta. So remove your multiplication by delta in

move_and_slide(velocity * delta)
by (1,314 points)

Thank you for the help, I'd missed that part of the docs

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.