godot icon indicating copy to clipboard operation
godot copied to clipboard

Add a setting to control applying area transform to gravity

Open lejar opened this issue 2 years ago • 3 comments

Change for #79243

This change adds a new parameter to Area3D, which determines whether or not the gravity calculation of an area should take the area's transform into account.

The default behavior before this setting was to take the transform into account when using the gravity is a point setting, but not when using a simple vector to specify the gravity. The new default value will be true in both cases.

I still need to add some logic to the project upgrade functionality which should disable this setting in older projects for areas using a vector to specify gravity, so that this does not break compatibility, but I couldn't find where this upgrade is done (except the one which upgrades godot 3 -> 4). I would appreciate if someone could point me in the right direction for this.

test_gravity.zip Here's a project containing the new setting showing how it works.

  • Bugsquad edit, closes: #79243

lejar avatar Jul 10 '23 05:07 lejar

Thanks for the contribution! The physics team is assigned for review, but it's currently short on contributors, so it might take some time. Feel free to drop by the #physics channel on the Contributors Chat to discuss your proposal.

For the record, your commit seems not to be linked to your GitHub account. See: Why are my commits linked to the wrong user? for more info.

akien-mga avatar Jul 10 '23 07:07 akien-mga

Should be added to the 2D physics as well for completeness IMO, if added

AThousandShips avatar Jul 10 '23 07:07 AThousandShips

Added the fact that this breaks compatibility by the default behaviour of the property, and it's change of behaviour with the point gravity if turned off

Can be removed if a converter is added, but that feels convoluted, and it still breaks compatibility by behavior, changing the default behavior, unless it is to fix a buggy behavior, breaks compat

AThousandShips avatar Jul 10 '23 07:07 AThousandShips

I've applied the requested changes to the 3D code. I'll work on making the same feature in the 2D code.

lejar avatar Jul 12 '23 05:07 lejar

Okay I've also gone ahead and implemented the same functionality into Area2D. I've updated my example project to include a 2D scene: test_gravity_with_2d.zip

lejar avatar Jul 12 '23 05:07 lejar

The documentation has to be in alphabetical order, you get this automatically if you compile the code and run --doctool on the compiled program

AThousandShips avatar Jul 12 '23 06:07 AThousandShips

Correct me if I'm wrong, but if this feature proposal had an associated Godot Improvement Proposal, then the answer to

If this enhancement will not be used often, can it be worked around with a few lines of script?

would be yes: store the original vector in a Vector3 variable on _ready, and apply the area transform whenever necessary, i.e. on _ready and whenever the area is transformed.

rburing avatar Jul 12 '23 07:07 rburing

That is true, reasonable workaround, maybe add it to the issue and we can discuss that part more there

  • #79243

AThousandShips avatar Jul 12 '23 07:07 AThousandShips