-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Allow all physics bodies to use the built-in gravity system #8054
Comments
I came across this PR while looking for the same solution. It seemed strange to me that the controller's gravity wasn't calculated in the same way as other rigid bodies. Anyway is there a reason why nobody has reviewed this yet? What's the usual time it takes to merge PRs into master? |
@letoast PRs often take years, this is only 2 weeks old, so that's why it has not been reviewed yet (not much time has passed). As with the play Godot is named after, contributing to Godot requires a lot of waiting and patience. But if you want to help this get prioritized, you can share it with your friends, on social media, etc, and they can click the 👍 button. |
Ahhh, sorry for the annoyance then. I'm more used to web projects where PRs get through relatively fast. Here's to hoping this gets noticed 🤞 |
For @onready var rid = get_rid()
func _physics_process(delta):
direct_state = PhysicsServer2D.body_get_direct_state(rid)
gravity = direct_state.total_gravity
velocity += gravity * delta which will also takes effect in an |
The solution proposed by @Lazy-Rabbit-2001 is simple enough, is sufficient for the task and is a positive answer to the question "If this enhancement will not be used often, can it be worked around with a few lines of script?". The property |
@Lazy-Rabbit-2001 @voidexp Thanks! I did not realize that API was available. I opened godotengine/godot#84640 instead, which will provide this as a helper method on physics bodies, simplifying the API, and yes I tested it and it works the exact same as the other PR. |
Implemented by godotengine/godot#84640. |
Describe the project you are working on
I'm working on support for dynamic gravity in Godot and in glTF to allow making games like Super Mario Galaxy. For more information, check out this video: https://www.youtube.com/watch?v=QLH_0T_xv3I&t=12m
Describe the problem or limitation you are having in your project
Godot has its own built-in gravity system. The world can have a specified amount of gravity, and Area(2D/3D) nodes can override this, either adding to it and replacing this, and multiple Area nodes have settings for what their priorities are and how well they play with other Area nodes. This is great!
However, right now the only bodies that can be affected by this are the dynamic RigidBody(2D/3D) nodes. Godot does not provide any way for the user to access the built-in gravity system, so there's no way to use Godot's built-in gravity system with CharacterBody(2D/3D) nodes unless you reimplement the whole thing.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a function to the PhysicsBody2D and PhysicsBody3D that allows the user to grab the gravity computed using the same code that the engine uses internally for RigidBody(2D/3D).
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Here is a fully working implementation: godotengine/godot#84640
Here is a fully working implementation: godotengine/godot#83087Here is an example of what can be accomplished. This is a CharacterBody3D node, being controlled by the gravity of Area nodes. The mini-Earth has a point gravity field, and the ramp has gravity fields to ensure the player sticks to it that override the gravity of mini-Earth.
gravity.webm
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, you would have to either reimplement the entire gravity system, which is unacceptable, or make all objects RigidBody(2D/3D) nodes, but I would really prefer to use CharacterBody(2D/3D) since they are designed for characters.As pointed out below, it is actually possible to work around this using a physics API that I did not know about before.
Is there a reason why this should be core and not an add-on in the asset library?
Godot's dynamic body gravity calculation is already in core, we just need to make it available for all bodies and expose it.
The text was updated successfully, but these errors were encountered: