How can I link weapon and it's rigid version for a throw?

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

Everything works for me as follows: I have a regular version of the weapon, and its rigid version in order to throw it.
Previously, for one weapon, I hid the weapon that was in my hands using the hide method. Then I spawned a rigid version of it in the same place as the weapon and applied the " " method. This solution worked very well when there was only one weapon. And I need to find out how I can automatically link these 2 versions of weapons.
I write the full code below.

func attack_check(): #Func which check attack or throwing
	if Input.is_action_just_pressed("Attack") and _is_picked == true:"MeleeAttack")
	if Input.is_action_just_pressed("Throw") and _is_picked == true:

func throw_weapon():#Func for throwing
	weapon_rigid = weapon._rigid#_rigid is a variable in weapon script
	throw_velocity = (mouse_pos - global_position) * throwable_speed
	throw_velocity = throw_velocity.limit_length(1700)
	weapon.get_node("Pivot/AreaForHits/Hitbox").disabled = true
	weapon_rigid.position = weapon._throwable_weapon_start_pos().global_position
	weapon_rigid.rotation = weapon.rotation
	weapon_rigid.apply_impulse(Vector2(0.0, 0.0), throw_velocity)
	_is_picked = false

func _collision_checker(body): #For RigidBody
	if _is_killed == false:
		if _is_picked == false and body.is_in_group("Weapon_throw"):
			weapon.get_node("Pivot/AreaForHits/Hitbox").set_deferred("disabled", false)
			_is_picked = true

I am sorry I am not sure I understand what you mean when you say you want to link them. Do you mean you want to attach them to each other with something like a pivot joint?

Gluon | 2023-02-02 23:16

Nope. I mean, when I pick up rigid weapon, it need to make a node version as a player child. And to make it work I need link those 2 rigid versions. For example, player have 2 weapons, pistol and shotgun.When player throw pistol, pistol node is hide and hitbox is disabled, and on this position we add rigid_pistol as a child. After throwing player want to throw shotgun too. He have shotgun node, which hiding after throwing and spawns rigid_shotgun. Player want to pick pistol first, and when he pick it he got a shotgun because it just show hiden weapon, when pick up rigid weapon. I need to link those 2 weapon versions because I want to player pick up pistol and not shotgun.
I don’t know english, but I hope you understood.

Nizil | 2023-02-03 08:14