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

CharacterBody3D move_and_slide use an hardcoded delta time #71999

Closed
Fabien2S opened this issue Jan 24, 2023 · 6 comments
Closed

CharacterBody3D move_and_slide use an hardcoded delta time #71999

Fabien2S opened this issue Jan 24, 2023 · 6 comments

Comments

@Fabien2S
Copy link

Fabien2S commented Jan 24, 2023

Godot version

v4.0.beta14.mono.official [28a2463]

System information

Win11

Issue description

move_and_slide() in CharacterBody3D uses an hardcoded delta time which make it impossible to apply multiple inputs in the same frame.

I'm developing a fast-paced multiplayer game in which I want to implement client prediction and lag compensation. I need a way to apply a list of inputs (or velocity) multiple times in the same frame with each of them responding to collisions. Each of theses inputs should be executed 0.05 seconds apart (delta time), but as the delta time is hardcoded this make it quiet challenging.

I may be doing something wrong here, perhaps something not supported, in that case please let me know.
The documentation says nothing about calling move_and_slide only once per frame or something like that.

Steps to reproduce

  1. See
    bool CharacterBody3D::move_and_slide() {
    // Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
    double delta = Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time();

Minimal reproduction project

N/A

@RemyCampanals
Copy link

I don't know why we don't have delta as an argument for move_and_slide() method, it could help if we want to create some slowmotion feature for our CharacterBody3D.

I think it could resolve many problems at once or i'm mistaken ?

@aXu-AP
Copy link
Contributor

aXu-AP commented Jan 25, 2023

Calling move_and_slide multiple times in a frame seems to work. But you need to handle the velocity yourself in some custom manner. Something along these lines (untested):

velocity = velocity / delta # Counteract default delta value
velocity = velocity * custom_delta # Add your own delta
move_and_slide()
velocity = velocity * delta / custom_delta # Get modified velocity

This of course is just a workaround, I too would see some value in optional delta parameter. However, I believe this should be in godotengine/godot-proposals to gauge it's need before implementing.

@Fabien2S
Copy link
Author

Fabien2S commented Jan 25, 2023

You're right, I should have posted this in godotengine/godot-proposals, my bad. I was quite tired when I posted this.

Thanks you for the workaround, I tried to do the same thing but used a for loop which called move_and_slide multiple times based on the difference of the two delta times, which was really not working (obviously)

Do you think I should close this and create a proposal instead?

@aXu-AP
Copy link
Contributor

aXu-AP commented Jan 25, 2023

Well, I'm not moderator or anything, so take that as a disclaimer. But that's what I'd do. Less headache for project management when everybody goes by the book.

@viksl
Copy link
Contributor

viksl commented Jan 25, 2023

Is that what move_and_collide is for? You utilize delta there for the vector input. Although you need to handle the custom behaviour on your own then.

@Calinou
Copy link
Member

Calinou commented Jan 25, 2023

This is done by design, just like in 3.x. This has been extensively discussed on GitHub issues in the past, though I can't find links to the issues in question right now.

I'm developing a fast-paced multiplayer game in which I want to implement client prediction and lag compensation.

You probably want support for manual physics simulation instead, which isn't implemented yet: godotengine/godot-proposals#2821

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants