#Dragging and dropping tiles. Having issues with the tile dropping exactly where I need it

3 messages · Page 1 of 1 (latest)

rare mist
#

As you can drag over multiple bodies at once you could store an array of the current hovered bodies, and on drop iterate over them / find the closest one etc.

var bodies_over := []

func _on_area_2d_body_entered(body:StaticBody2D):
    if body.is_in_group('droppable'):
        bodies_over.push_back(body)
        ...

func _on_area_2d_body_exited(body):
    if body in bodies_over:  
        bodies_over.erase(body)
        ...
fleet birch
#

Exactly. If you step through your video frame by frame, you'll see your draggable snaps to the tile it touched last.

slim path
#
                var closest_distance = INF
                for point in drop_points:
                    var distance = global_position.distance_to(point.global_position)
                    if distance < closest_distance:
                        closest_distance = distance
                        drop_point = point
                tween.tween_property(self, "global_position", drop_point.global_position,0.2).set_ease(Tween.EASE_OUT)```