How do I make a collectable move to the position where the counter is located in UI?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Magander86

I want a collectable to move to where the counter’s position in UI is located, like in SNES Donkey Kong Country.

Donkey Kong gameplay

This is how my game is executing:

https://i.imgur.com/LHhowTQ.gifv

This is the code:

extends Area2D


onready var fruit_UI = get_parent().get_parent().get_node("GUI/Control/FruitCount/Fruit")

onready var fruit_UI_pos = fruit_UI.global_position

var is_moving = false

var direction
var speed = 350

func _ready():
 direction = (fruit_UI_pos - global_position).normalized()


func _physics_process(delta):
 if is_moving:
	global_position += direction * speed * delta

func _on_Fruit_body_entered(_body):	
 is_moving = true
:bust_in_silhouette: Reply From: exuin

The problem is that the camera and the UI moved, but the direction wasn’t updated. You’ll need to update the direction in the _physics_process function as well.