A plugin/addon for Godot which adds support for fairly realistic point gravity physics (currently only in 2D).
Godots built-in "gravity point" physics can be hard to build around. Some issues I have found are:
- only Area2D can have the physics behaviour attached to it
- to set this up you have to have a large collision shape on the Area2D for gravity to be detected
- there's a bug which means that gravity isn't realistically calculated godotengine/godot#30575
- this means you can't setup stable orbits
This plugin offers an alternative way of creating point physics.
- Godot 3.x
- Download the latest release from the releases page
- Unpack the zip into your project into
./addons/gravity_bodies/
- Check the plugin has been imported successfully in Godot
- go to Project -> Project Settings... -> Plugins -> find Gravity Bodies (and Enable)
- Create a new scene in your project with a root node (such as Node2D)
- Add a gravity body to the root
- Add a child node to your root
- Either add a GravityBody2D node
- Or add a RigidBody2D node and attach the script from
res://addons/gravity_bodies/GravityBody2D.gd
- Give your new node a collision shape
- Give your new node something visual like a sprite
- Repeat step 2 (but make sure nodes aren't overlapping
- Add a child node to your root
- Run the project
Each gravity body should be attracted to each other.
You can configure how the gravity is setup with the following properties on a GravityBody2D node:
This property changes how much this node pulls on other gravity bodies.
I recommend setting the mass
property rather than gravity
property.
Changing this property will produce unpredictable/unrealistic physics so use with caution!
Example: setting this property to 0.5 will reduce the gravity given to another particle by half.
Similar to changing how much this node pulls on other gravity bodies.
Multiplies the gravity applied to this body.
Different bodies can be placed on different collision layers / masks to change which bodies attract each other.
These examples can be tested by running them from the ./examples
folder.
solsystem.mp4
binarysystem.mp4
falltest.mp4
gravitydistancescale.mp4
gravityscale.mp4
- the performance of this plugin is likely to be far worse than the built-in gravity
- Gravity Distance Scale feels pretty broken
Many thanks to https://github.com/ApocalypticPhosphorus/Godot-3D-Gravity as a base to start from.
Feel free to submit issues / pull requests though I (the maintainer) will likely have moved on from this project.
The code could quite easily be modified to work in 3D (but I have no need for that right now).