Connecting two kinebodies2d together using signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ruben_K

heyy guys beginner here, and a long question sorry. I want to connect a kinebody2d(player.tscn) to another kinebody2d(block.tscn), where if it enters the area2d area around the block by pressing “enter” it connects to it like a magnet, but can still control the player movement with the block attach, and then disconnects from it when you hit “enter” again. Thnx in advance

:bust_in_silhouette: Reply From: Pomelo

Aside from the functonality of what you want to achieve, I suppose you are asking how to connect signals? and how to detect being in an area2d? and how to trigger the send signal when pressing enter? Try to be more specefic with what is that you are having problems.

You can connect signals in the editor or by code, you can read about it in the docs, and ask here again if you have problems with it. you would have to conect a custom signal between the player and the block (to inform the block that entere was pressed, so the block can engage and disengage).

There are many ways to know if you are inside an especific area. For example triggering signals of body entered and body exited and saving that info on a var on the player.

Once you have that info on the player, just check for it with an if statement when pressing enter, and if true send the signal to the block.

First manage these 3 steps and check if the whole thing is working, and then move to what you want to do with the actual block.