Apply gravity from one scene to another

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

I have figured out how to turn gravity off and push a little spaceship around a planet and moon. My problem is that I can’t figure out how to set the planet (and eventually moon) to act like point gravity sources and interact with the ship. The planet scene contains an area2d that says it is acting like a point gravity source, but it doesn’t seem to have any effect on the ship scene.

The current state of my files can be downloaded here:
https://github.com/jwinterm/MoonLaunch/releases/download/v0.1/MoonLaunch.zip

or seen here:

:bust_in_silhouette: Reply From: kidscancode

I notice a few things on looking at your project files:

  1. An Area2D must have a CollisionShape attached. This is how you define its area of influence.

  2. When using RigidBody2D (for your rocket), you should use _integrate_forces() instead of _fixed_process() for code that affects the physics state.

I recently did a tutorial on using RigidBody2D that you might want to take a look at:

It includes using an Area2D for point gravity.

Thank you for the quick response. Your video was very helpful in understanding the way to approach this.

If I wanted the planet to move during gameplay, would I just make the root node for the planet scene a kinematic body, and then put the area2d as a child node to that? Because, as far as I saw you can not translate or reposition an area2d.

Also, you link part 14 in the direct download section of your youtube comments instead of 15, btw.

jwinterm | 2017-09-10 16:35

You can move an Area2D - you just update its position:

set_pos(get_pos() + Vector2(100, 0) * delta)

If all you need is for it to move, and not collide, then that’s simpler than also using a KinematicBody.

Thanks for the tip on the link!

kidscancode | 2017-09-10 16:43