godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Externalize calculation of frame delta from `move_and_slide()` as a required velocity parameter (Godot 4) #9663

Open lokimckay opened 2 weeks ago

lokimckay commented 2 weeks ago

Describe the project you are working on

A multiplayer 3D RTS game that uses differing tick rates for different objects

This issue was already raised here https://github.com/godotengine/godot-proposals/issues/1192, but much of the discussion is about Godot 3's move_and_slide which allowed passing of velocity as a parameter. In contrast, Godot 4's move_and_slide does not accept any parameters, which causes this issue.

Describe the problem or limitation you are having in your project

Minimal reproduction project

It is impossible to use move_and_slide in a deterministic way because it multiplies by frame delta internally - which forces floating point math to be used

In contrast, modifying a Node's position manually or using move_and_collide can be done without any floating point math because frame delta is not considered

Imagine a project with this setup:

  1. Physics frame rate via project settings set to 60 FPS
  2. Our most important objects move_and_slide on every physics frame as normal - no issues
  3. We have other less important objects that we would like to move_and_slide every 10th physics frame
  4. We implement a system that cumulates pending physics frames in order to multiply their count against the move_and_slide velocity
  5. Since move_and_slide multiplies the character's velocity internally, small floating point errors will be introduced between the important and unimportant objects - which will eventually manifest as desynced positions

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Remove frame delta calculations from move_and_slide:

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. Remove delta from move_and_slide as described above
  2. Document expected usage of move_and_slide as follows:
extends CharacterBody3D
var speed = 1

func _physics_process(delta):
  velocity.x = speed
  move_and_slide(velocity * delta)

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

move_and_slide is a core engine function

Related

AThousandShips commented 2 weeks ago

Nite that #1192 was rejected specifically because it suggested removing delta from the move_and_slide method, how is this different, it sounds very much the same

lokimckay commented 2 weeks ago

1192 was rejected specifically because it suggested removing delta from the move_and_slide method,

1, I was instructed to open a new proposal in #1192

  1. I don't see that reason for rejection explained anywhere in #1192

how is this different, it sounds very much the same

The goal is the same, but this proposal has a few differences:

  1. More current - as I mentioned above, the discussion in #1192 is explanations for how to workaround the problem in Godot 3 - which are now impossible in Godot 4
  2. Minimal reproduction project
  3. Better explanation of a use case that cannot be achieved currently