Getting position of sprite

Godot Version

4

Question

I managed to get distance calculated with my cursor, but realized I need it to measure the distance of the sprite itself. However I cannot figure out how to get the position of the sprite.
This is my drag/drop code with measuring

extends Sprite2D

var is_dragging = false
var mouse_offset # on click
var delay = 5
var distance
var initial_pos
@export var inches: float

func _physics_process(delta):
if is_dragging:
var tween = get_tree().create_tween()
tween.tween_property(self, “position”, get_global_mouse_position() - mouse_offset, delay * delta)
inches = (initial_pos.distance_to(get_global_mouse_position()))/100
print(inches)
func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
if get_rect().has_point(to_local(event.position)):
is_dragging = true
mouse_offset = event.position - position
initial_pos = get_global_mouse_position()
elif event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
is_dragging = false

The distance from the sprite to the sprite is 0, it is at the same position of “itself”

If you are trying to measure the distance toward some other point you can use Vector’s distance_to function

global_position.distance_to(other_object.global_position)

If this script is attached to the sprite then using position or self.position will get the position, like you’ve used before in calculating mouse_offset

mouse_offset = event.position - position

Make sure to format code pastes

That worked, thank you.