0

Big noob on godot and dev in general, so sorry for my abysmal incompetence. https://i.stack.imgur.com/BEa7y.jpg

I'm trying to do something that looks fairly simple (which I'm learning to be never true in gamedev) Grab an object (In that case a "connector" like a USB male), and when I get that object to a "zone" (an "input" USB female): the object would snap to that zone and be released from the mouse. The way I tried to do it, is by creating an area2D on the input, with a collision shape (fig1). Then, I sent a "body_entered(body:Node2D) signal from this area to the "Connector" node. (fig2)

On the connector script, under "func _on_area_2D_body_entered(body)" I just tried different things, but it never seemed to do anything. So I tried to add a "print('hello')" to see if the "collision" was happening at all. But nothing prints when I grab the connector and get it to the input position.

Is there something wrong with my script or the way I'm sending the signal?

extends Node2D

var selected = false
var rest_point 
var input_pos

func _on_area_2d_input_event(_viewport, _event, _shape_idx):
    if Input.is_action_just_pressed("click"):
        selected = true

func _ready():
    rest_point = global_position
    input_pos = get_node("root/Level/input")

func _physics_process(delta):
    if selected:
        global_position = lerp(global_position, get_global_mouse_position(), 25*delta)
    else:
        global_position = lerp(global_position, rest_point, 10*delta)

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
            selected = false



func _on_area_2d_body_entered(_body):
    #rest_point = input_pos.global_position
    print('hello')

I tried to put the name of the specific node I wanted to target entering the area2D putting it like this: func _on_area_2d_body_entered(Connector):

But it didn't change anything.

I'm basically just trying to get a response from the signal right now. It's like the signal is not working.

1 Answers1

0

I found my mistake! The "body_entered" only work with a Physicsbody2D or a Tilemap My connector is a simple Node2D so even if it had a collision shape, it was not triggering the signal.