Global_position with raycasts and draw_line

Godot Version

4.2.2

Question

Hello all, had a quick crisis earlier today when I thought that I was doing my raycasts all wrong, but then figured out something odd that I must be missing.

When making a raycast in gdscript, I used this:

var query = PhysicsRayQueryParameters2D.create(los_raycast.global_position, tethered_object.base_collision.global_position,
		0b00000000_00000000_00000000_00000011, [anchor])

It shoots a raycast from the base of player to the object that they are tethering to. I know it works, I’ve tested it and if something in the correct layer gets in the way, the tether breaks.

I was working on another addition, and was wanting to better visualize the raycasts that I was using, so I wanted to use the draw_line, and pass in the same variables, but it places the lines in different spots.
test
The code for the lines was:

draw_line(los_raycast.global_position, tethered_object.global_position, Color.YELLOW, 1.0)

It seems the beginning point of the line is twice the distance from the world center to the beginning point, and then the end point is the distance and angle from the world center to the end point, not the distance from the beginning point to the end point.

This also happens if I instantiate an object at “self.global_position”, it will appear at twice the distance from the world center to the player.

Howcome this happens with draw_line and instantiating objects, but not with raycasts? Is there just an option I am missing, or am I fundamentally misunderstanding global_position?

This also seems to be the case if I try to instantiate an object based upon the collision from a raycast I create.

var object = test.instantiate()
			object.global_position = beam_raycast_result.get("position")
			add_child(object)

I’d assume it’s because I am adding the object as a child of another object, so it’s getting the position of the collision, and then adding the transform position of the parent? I can fix it with:

var object = test.instantiate()
			object.global_position = -(self.global_position - beam_raycast_result.get("position"))
			add_child(object)

But if there’s any better options that’d be great to know.

Im pretty sure lines work with local coordinates, so you would have to figure out what the local coordinates of these are. Im not 100% sure though, but you should give it a try