planet simulator using physics

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By swipis
:warning: Old Version Published before Godot 3 was released.

Hello,

I curious how to make planet to be as gravity point that attracts moon (or other object). I think that I need to use Area node (but not sure). Please can someone point me to the right direction? (I guess 2D or 3D works in similar way)

Thank you

:bust_in_silhouette: Reply From: eons

Area space override gives you options to add, replace and combine many properties like gravity (even use negative gravity to expel, simulate water and add damp for density/simulate 3D surfaces on 2D).

Do some tests, make an area with space override and put a body in direction of that area to see how works.


But is hard to control this, also while debugging, the physics may work a bit wrong and the effect could be different on release, so may be better to simulate orbits in a complete fake way instead of letting the physics engine to do it, let the engine work alone where you don’t care of the results.

Still, you can use Area information for your calculations, on process or with a custom integrator (rigid) to control and force objects to keep an orbit.


Here is an example of something that only happened to me while debugging (there is an area with gravity replace and point, centered on the planet, the rest are rigids):
https://twitter.com/_eons/status/755100860313722880

Here is a small word in 3D, “bullets” are rigids affected by Area gravity point:
https://twitter.com/_eons/status/746046465357778944

Thank you eons for answer I trying to test as you said but no luck at all. please maybe you can explain in detail how to set up scene? for now I have area node (test cube is a child) and another node is rigid body and what I trying to do simply rigid body falls near area and if I understand correctly area should pull rigid body?

swipis | 2017-04-13 18:40

To make things easier at first, put the general gravity on 0 at project settings so you don’t have to deal with replace and combine options because are a bit confusing.

Turn on collision shape visibility on the editor debug options (to make things faster).

  • Make a root like always (Node, Spatial, anything).
  • Add an Area with any shape (better box or sphere to have an idea of what is happening), make it big. Put space override on combine or replace and check gravity point (to make a central gravity).
  • Add a RigidBody far from the area center but inside the area (not a child, in shape), add a shape so you see it.
  • Add more rigid bodies inside and outside the area shape.
  • And of course, a camera to see the scene.
  • If you turn on sync scene changes, you can play with area gravity values on the editor and watch the effects on the running scene.

Then you can make it more pretty with meshes, some static or kinematic bodies on the area center, that way it will look like if the rigids are attracted by an object.

eons | 2017-04-13 19:32

thank you for your time but still nothing… do not understand or I doing something wrong or what happening :smiley:
here is an image what I done (and if you will see what I dong wrong please tell me):
my scene

swipis | 2017-04-13 20:36

If the central one is the area, make it bigger so it affects the bodies (need to touch them).

Deformed shapes may not work well, btw, try to do uniform scales (same x and y) or use a polygon.

Some bodies ignore scales too, is better to change shape’s size instead.

eons | 2017-04-13 23:26

I stuck and not sure why nothing happening… I will look for some examples on the internet.

Thank you eons

swipis | 2017-04-14 06:23

Save this as a tscn file
http://pasted.co/6b8d6199

You may need more practice with the basics before suffering the physics engine ^^;

eons | 2017-04-14 13:27

ohh I see now what I did wrong I made area it self big not and collision shape wasn’t . just one simple question if I change rigid body mode to kinematic area not attracting, this works just with rigid bodies?
Thank you!

swipis | 2017-04-14 14:23