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