Skip to content

Calculate gravity based on distance from body to gravity point

Rafał Mikrut requested to merge github/fork/Faless/gravity_distance_full into master

Created by: Faless

This patch allows to scale the gravity applied by a gravity-point Area/Area2D based on the distance from the gravity-point to the body, thus simulating the basic law of gravitation.

The formula applied is: gravity = area_gravity / (distance * scale_factor + 1)^2 This ensures that the maximum gravity applied cannot be more then the user specified one (and avoid good old divisions by zero). If scale factor is 0 (default) the usual system (no distance scale) is applied.

You can test the patch with the following demo: https://github.com/Faless/godot_demo Notice specifically the differences between demo 1 and 2 and demo 3 and 4

Merge request reports