0 votes

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:


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
Godot version 3.2.3
in Engine by (12 points)

1 Answer

0 votes

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.

by (7,839 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.