Godot Version
Godot 4.4
Question
Hello, I am trying to make a game where I drag arms and grab coins and put them in a purse. I am having trouble, I have seen online that area2d is not physics body, so my “workaround” was to instantiate a new coin when the character area collides with the coin area, then delete the coin, and make the instance a child of the character while they are moving with my character and mouse while we all drag along, then, when they were over the purse (or) if they were putting their hand to their purse area2d they could deposit the coin.
Which I then attempted to set up to have it remove the child and add the child to the level node through a signal. I have gone back and forth and the closest I got to feeling like I was onto something was where I switched the collision_mask but it just made the coin disappear. Even though I printed the location and it was right there. I saw some stuff about it but not sure what I’m doing wrong. Thank you for reading this paragraph, here is the code:
var coin_grabbed = null
signal just_dropped_coin(this_coin)
@onready var coin_scene = preload("res://scenes/coin.tscn")
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("DROP_COIN") and instance:
self.remove_child(instance)
just_dropped_coin.emit(instance)
if instance != null:
instance.global_position = self.global_position
#the grabbing and dragging seems to be fine but without the other part may as well not be
func _on_area_2d_area_entered(area: Area2D) -> void:
if area.is_in_group("Coins"):
instance = coin_scene.instantiate()
timer.start(2)
coin_grabbed = area
instance.global_position = self.global_position
add_child(instance)
area.queue_free()
#Then in the game world script I have the signal connecting
func _on_just_dropped_coin(this_one_right_here) -> void:
add_child(this_one_right_here)
I’ve tried to include many things in this function. I feel like I’m jamming the square peg in a round hole. I tried to add a directional vector to it so maybe it would “jump” out of the touch zone, because I think what’s happening is my area2ds are just recontacting as soon as the conditions are right for them to separate and they reparent together. But I’m not sure, I couldn’t even figure out how to then find the new instantiated child node, I managed to get an array of children but I’m clueless. Is the problem so obvious to change to rigidbody? is there anything anyone could think I may need to look out for with that route? Any advice is much appreciated