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

Area2D/3D Gravity: Replace point bool with a type enum, add Target gravity type #82878

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Oct 5, 2023

This PR implements godotengine/godot-proposals#7850 and godotengine/godot-proposals#5714

In the current master branch of Godot, there are only two types of gravity: Directional and Point. Godot does not provide a way for users to implement any other gravity type. This PR allows doing this, by adding a new gravity type called Target that allows specifying the gravity's attraction target point with a callback method.

To be clear, the goal here is to add the minimum engine code required to allow user scripts to make their own gravity. The goal isn't to implement every possible gravity type in the engine code, just let users implement what they need.

This PR is split into 2 commits for easy reviewing:

  • Replace Area gravity point bool with a gravity type enum. This is a refactor that does not change behavior or break compatibility. A bool does not make sense here, because conceptually there are more than two possible states for gravity, and conceptually it does not make sense why one is more deserving of the true state (there could just as easily be an "is directional" boolean instead of an "is point" boolean).

    • If desired I could split this into its own PR.
  • Add a Target gravity type to Area for a custom target point. This adds new behavior and implements the proposal. The attraction target of the gravity is defined by the return value of the callback method. The reason it seems like there's a lot of changes is due to all the places that need to know about this (Area nodes, physics servers, physics servers wrap_mt, Godot physics engine, physics server extensions), but it's not much code compared to the existing directional and point gravity.

I have tested this in both 2D and 3D. I am planning on using this in 3D for implementing custom gravity in script.

@aaronfranke aaronfranke force-pushed the gravity-target branch 2 times, most recently from e8f282b to 165586b Compare February 22, 2024 07:50
@aaronfranke aaronfranke modified the milestones: 4.3, 4.4 Jun 14, 2024
@aaronfranke
Copy link
Member Author

@mihe I was told by @fire to request your review on this PR.

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

Successfully merging this pull request may close these issues.

Add custom gravity calculation in Area3D/Area2D
2 participants