How do I add gravity to an Area2D node

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

I’ve been learning coding for a little under a year now so i don’t know a lot. What I want to ask is that how do I add a area2D node.

:bust_in_silhouette: Reply From: kidscancode

It’s hard to know exactly what you’re asking.

  1. “how do I add a area2D node” - I assume this isn’t really your question, but you click on the “Add Node” button in the Scene panel.

What I think you might be asking:

  1. How do I make an Area2D node change the force of gravity on bodies that enter it?

The answer is in the Area2D properties in the Inspector. You can set a value for Gravity (its strength), Gravity Vec (its direction), and Gravity Point (if you want gravity to point to the center of the Area2D). See also the Space Override property to control how the area interacts with the global gravity.

  1. How do I make an Area2D fall as if it’s being acted on by gravity?

If you want to move an area, you have to do it manually in GDScript:

extends Area2D

var gravity = Vector2(0, -100)  # gravity force
var velocity = Vector2()  # the area's velocity

func _process(delta):
    velocity += gravity * delta 
    set_pos(get_pos() + velocity * delta)

I added gravity, but I don’t know how to get kinematic/physics bodies to react, they just float there. Could you please help? I’m very new to godot.

a human | 2019-05-11 23:20

You should probably ask your own question rather than replying to one that’s over a year old.

Kinematic bodies aren’t affected by gravity or any physics. You have to move them yourself.

Read this: Physics Introduction

Then read this: Using KinematicBody2D

kidscancode | 2019-05-11 23:23

Can you please give an example of how you might do this (part 2)? I am trying to do the same thing (affect rigid body using area2d point gravity) to achieve a ‘gravity slingshot effect’, and have found no way to do this.

Elliot__C | 2021-02-22 13:03