![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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.
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