Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lokimckay opened this issue May 3, 2024 · 4 comments
Labels
breaks compat Proposal will inevitably break compatibility topic:physics

Comments

@lokimckay
Copy link

lokimckay commented May 3, 2024

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 #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:

  • removing this line from move_and_slide
  • removing any mentions of delta in that same function
  • have that function accept a velocity parameter in the same way that move_and_collide does

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 AThousandShips added topic:physics breaks compat Proposal will inevitably break compatibility labels May 3, 2024
@AThousandShips
Copy link
Member

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
Copy link
Author

#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
2. 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 move_and_slide() should not implement delta on its own #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

@Truc4
Copy link

Truc4 commented May 21, 2024

I second this, when working with tick based physics system for network synchronization, it is very annoying of the server happens to lag during the single frame that the rollback is supposed to occur. This causes very wild over compensation and I do not know what alternative I have other than to rebuild Godot.

@Truc4
Copy link

Truc4 commented May 21, 2024

I don't know if it will help anyone but this is the branch I am currently using for my project and it seems fine. I can finally get consistent move_and_slide when calling multiple times a frame.

https://github.com/Truc4/godot/tree/4.2.2-move_and_slide-external-delta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Proposal will inevitably break compatibility topic:physics
Projects
None yet
Development

No branches or pull requests

3 participants