Hello, I am encountering a problem that I do not understand, I have 2 scenes, 1 with a large object which has a 2d area and another with a small object that I can move with my mouse, it has been 2 hours since I tried to do that if I put the small object in the large object or message is displayed in the console but I can't find a solution. If anyone can help me I would appreciate it.
#Area 2d dont work
1 messages · Page 1 of 1 (latest)
I don’t quite understand the issue from your wording. What should be happening? And what wrong thing is happening instead?
so I want that when the object on the right enters the object on the left a message appears in the console like "objcet 1 entered object 2"
Okay. Did you connect the area_entered signal?
yes I tried and it doesn't work for me that's why I don't understand XD
Show the code
var mouse_offset
var selected = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if selected:
followMouse()
func followMouse():
position = get_global_mouse_position() + mouse_offset
func _on_area_2d_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
mouse_offset = position - get_global_mouse_position()
selected = true
else :
selected = false
func _on_area_2d_body_entered(body):
print("object 1 is in object 2")```
this is the code for the object on the right
did you change the collision layers perhaps?
they are in the first layer
you need to use area_entered signal, body_entered is for collision with physical bodies. both objects you have are areas