+1 vote

In my game, the world is divided into multiple rooms, each with an Area2D that encapsulates its bounds. I want to be notified (preferably via signals) when a specific point (e.g. Position2D) enters each rooms so that I can keep track of where my player character is and react accordingly with e.g. the camera.

I'm currently using the character's CollisionShape2D and Area2D's body_entered signal to achieve this, but it would be better if I could know when the center of the player enters the room, rather than when the edge of the player does so.

Is this possible without having to e.g. constantly query each room and check whether the player's current position lies within the bounding box?

Thanks in advance!

in Engine by (45 points)

Couldn't you use a smaller collision shape inside the player just for this? By using the Layer and Mask properties you could avoid the area to detect the bigger shape.
Just what came to my mind :/

I considered this, but I really would prefer it to be a zero-dimensional point, rather than a two-dimensional shape, so that it would be impossible for the character to exist in two rooms at the same time.

If size of the RectangleShape2D is Vector2(0.5, 0.5)(1 pixel) , Player cannot be in two separate rooms at the same time. Pixel snapping should be turned on and rooms should be in integer size. Then You can know which room you are in by using one of the area_entered(), area_shape_entered(), body_entered() signals. The size can be adjusted from the editor, or with script;

extends CollisionShape2D

func _ready():
    shape.extents = Vector2(0.5,0.5)

Please log in or register to answer this question.

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.