+1 vote

The object is in type of "StaticBody2D", and as for the area , i plan to use "Area2D".

Do you know how to detect when the object enters the area in codes?

I'm new to godot. Thank you!

in Engine by (13 points)

1 Answer

+3 votes

StaticBody2D is not meant for an object that can move, I suggest you use KinematicBody2D or RigidBody2D.

Area2D has a signal you can connect to, body_enter: http://docs.godotengine.org/en/latest/classes/class_area2d.html?highlight=body_enter#signals

You can connect it from the Node panel (or in code with connect()) to a method of your script and it will be called whenever a body enters the area.

by (27,666 points)

Thank you. I followed the tutorial from here which is very long to read. Mostly I created an Area2D node, then added a subnode "CollisionShape2D", and I adjusted the shape within the area I want to take care of in the scene file ( say "my_scene.xml") .

And my codes are here:

http://imgur.com/a/6yTHR

enter image description here

Honestly I am a little confused about the doc because it doesn't have examples in details like charts or images. But it is helpful. Thank you!

With an area, you can use get_overlapping_areas and get_overlapping_bodies inside fixed process code too.

http://docs.godotengine.org/en/stable/classes/class_area2d.html#class-area2d-get-overlapping-areas

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.