Player not dropping weapon in the direction im facing

Godot Version

4.3

Question

I got my drop weapon function to work, and my weapon now drops into the world and i can pick it up again, the problem is the weapon tends to not drop in the direction i am facing, and always seems to drop in just weird inconsistent areas, but it most consistently drops where im facing when i first load into the scene, im thinking it may not be updating my position correctly but i cant figure it out for the life of me. I started coming up with an idea to drop from the crosshair position instead of the relatvie player position but that doesnt seem to work either, youll see that code below.
DROP SCRIPT vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Drop weapon

func drop_weapon():
if is_dropped:
return
# Ensure the sword is not inside the tree before dropping
print(“Is sword inside tree?”, self.is_inside_tree())
if self.is_inside_tree():
print("Removing sword from current parent: ", self.get_parent())
self.get_parent().remove_child(self) # Remove sword from player
self.set_owner(null) # Unset the owner of the sword

 # Now we add the sword back to the root
var player_scene = player.get_parent()
if player_scene:
	print("Adding sword to player's scene...")
	player_scene.add_child(self)
else:
	print("Failed to get the player's scene")
	return
	
   # Get the crosshair's screen position (2D)
var screen_position = crosshair_position

# Convert the 2D screen position to 3D world space using the camera
if camera_3d:
	var ray_origin = camera_3d.project_ray_origin(screen_position)  # The ray origin in world space
	var ray_direction = camera_3d.project_ray_normal(screen_position)  # The ray direction
	var drop_position : Vector3  # Declare the drop_position variable here

	# Perform the raycast to get where the sword should land
	var ray_end = ray_origin + ray_direction * 10  # Make the ray travel a bit, adjust distance as needed
	var query = PhysicsRayQueryParameters3D.create(ray_origin, ray_end)  # Create the query
	var result = get_world_3d().direct_space_state.intersect_ray(query)
	
	if result:
		# If ray hits something, use the hit position
		drop_position = result.position
		print("Ray hit at position: ", drop_position)
	else:
		# If nothing is hit, use a default drop position in front of the player
		var player_forward = player.global_transform.basis.z.normalized()
		var drop_distance = 2.0  # Adjust how far in front of the player the sword should drop
		drop_position = player.global_position + player_forward * drop_distance
		print("Ray hit nothing, using fallback drop position:", drop_position)
# Now set the sword's position
	self.global_position = drop_position

Mark the sword as dropped

self.is_dropped = true
 # Scale up the sword temporarily for debugging
self.scale = Vector3(5, 5, 5)  # Make the sword 5 times larger (adjust as needed)
	
rigid_body.angular_velocity = Vector3.ZERO  # Ensure no spinning from previous interactions
	
rigid_body.visible = true  # Make the RigidBody3D visible when dropped
rigid_body.freeze_mode = RigidBody3D.FREEZE_MODE_STATIC  # Allow physics to affect the sword now
rigid_body.set_physics_process(true)  # Enable physics processing to let the sword fall


	 # Debugging: Print the position to ensure it’s correctly placed below the player
print("Sword dropped at position: ", self.global_position)
print("Player position: ", player.global_position)
print("Camera forward vector: ", camera_3d.global_transform.basis.z.normalized())

	# Disable the 2D sprite
animated_sprite_2d.visible = false
 
 # Disable attack functionality because the sword is now dropped
can_attack = false  # Ensure the sword can't attack when dropped