How do you make an Area2d Node fall?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sumguy05

Or move at all? I tried the gravity options in the inspector don’t affect the Node at all.

:bust_in_silhouette: Reply From: p7f

Area2D dos not get affected by gravitu because its movement is not handled by physics engine. Only RigidBodies get moved by engine. You can make an area fall defining a gravity variable and on _physics_process(delta) handle the fall manually. Like this:

extends Area2D
var gravity = 900
var velocity = Vector2()
func _physics_process(delta):
     velocity.y += gravity * delta
     position.y += velocity.y * delta

This is very simple snippet for reference only. Gravity is multiplied by delta for getting speed and again for delta ti get position.
However this wont make the area stop falling when colliding. If you tell me what you want to accomplish i can help you more. Perhaps is better suited for you a RigidBody2D or a KinematicBody2D.

LOL see my other question How do i get a falling RigidBody2d to detect a collision from the side? - Archive - Godot Forum

Basically i can get a rigid body to fall but the collision detection doesn’t work correctly.

I also tried your strategy first i got an error for using gravity as a variable name. When i changed it it still didn’t work.

sumguy05 | 2019-01-04 02:43

Oh, i did not see that. Anyways, i think RigidBody2D should detect collisions by side also… can you share the project? And did the code to make the area fall worked?

p7f | 2019-01-04 03:40


I had a typo it did work. Thank you.

*Edit 2

Now the body entered isn’t working at all for the Area2d lol. Code below. The signal is connected to the snowflake.

func _on_snowflake_body_entered(body):
if body.get_name() == "player":

3rd and final edit. Everything all works. I had to re add the collision shape for some reason but it works.

sumguy05 | 2019-01-04 03:44

I’m glad it worked!
Just a comment… if your area are snowflakes, you may give them constant velocity instead of gravity, as snowflakes in real world are so light that friction with air make them fall at constant speed. Emulating gravity like i said will make them fall faster and faster.
If my answer is correct you may select it ao others see it worked.

p7f | 2019-01-04 10:56