-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Expose a method to get gravity for any physics body #84640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested suggestions, but the C# template was inconsistent with gdscript.
modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs
Outdated
Show resolved
Hide resolved
modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs
Outdated
Show resolved
Hide resolved
3934194
to
6877c75
Compare
6877c75
to
2f22a5f
Compare
2f22a5f
to
aedd9b1
Compare
aedd9b1
to
aed5ea9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the 2D part and it works correctly. The updated script template is a nice touch.
Thanks! |
I was wondering why my review comments were going ignored, but apparently I had forgot to actually press the "Submit review" button. I guess I'll just dump my comments here, in case it's of any interest to anyone: I believe using You also can't actually use godot/servers/physics_3d/godot_physics_server_3d.cpp Lines 923 to 924 in 63d6bda
What you likely should be doing instead is to add this as a variable in the scene nodes (like You can see other examples of things being synchronized here: godot/scene/3d/physics_body_3d.cpp Lines 493 to 507 in 63d6bda
The problem with this approach is that you also want this new What the solution to that problem would be isn't super clear to me. From what I've observed these state synchronization callbacks only get invoked when kinematic bodies actually move, and not continously, which would obviously be required for this accumulated gravity to be accurate, since you could have areas flying around all over the place (and affecting gravity) while the character is standing perfectly still. I would also perhaps question why this new method is called |
This comment was marked as outdated.
This comment was marked as outdated.
@mihe Thanks for looking into improving this! I think you're a lot more familiar with this code than I am, I'm inclined to go with your suggestions. Adding a variable in the scene nodes makes sense to me. |
Note the caveat with regards to kinematic bodies though. This could all be changed of course, but the performance implications are not trivial. The state synchronization is already quite an expensive part of the whole physics machinery once you start adding a lot of physics bodies. I'm not sure what other alternatives there are though. |
I only just now realized that this change encompasses |
I managed to create a repro for this desync issue in #87996, in case anyone wants to see it for themselves. |
@mihe Should we change the method to show an error when it's used outside of |
I must admit I don't love the idea of having a method on the physics bodies that's only okay to use during The only way of detecting whether this new method is safe to call would be to either expose some new getter on the physics server interface to get at what Godot Physics calls the I would probably opt for the |
This PR exposes a new method for getting gravity on physics bodies, and uses it in the script templates.
Implements godotengine/godot-proposals#8054 see the proposal for the justification.
Supersedes #83087 (but keeping it open for now, in case the internal code reorganization is helpful).
Minimal test project: character_gravity.zip (but replace "compute_gravity" with "get_gravity")