How to add gravity to area node?

4.3

I’m trying to make an enemy scene (Area2D), and I want it to spawn mid-air and then fall on the ground. How can I do that? I tried

if not is_on_floor():
	velocity += get_gravity() * delta

but is_on_floor() does not work on Area2D nodes unlike CharacterBody2D nodes. So I searched up a tutorial and didn’t find one applicable to Area2D nodes. Thanks!

Areas are only used to check which objects are inside of them, so they don’t have things like collisions
Try with a character body instead

1 Like

Like you observed, there is no is_on_floor() method on the Area2D, but there is on CharacterBody2D.
Why don’t you want to use CharacterBody2D for your enemy? That’s a standard practice.

Because I want the enemy to sense when the player touches it.

(I think Brackeys did a similar thing in his tutorial.)

Because I want the enemy to sense when the player touches it.

(I’m pretty sure Brackeys did a similar thing in his tutorial.)

Then just add an area inside a CharacterBody3D (Enemy), then you can use it for your purpose.

1 Like

I didn’t know I could do that… Thanks!

2 Likes