Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.
How can we prevent multiple triggers of animate_to_uiDelwinIf we wiggle with the mouse over the coins, we may trigger multiple animate_to_ui calls with the coin stopping and the tween transition starting again.
From my understanding setting "monitorable" to false in animate_to_ui() should solve it, but I still expierence the beahvior. Same if I disable the CollisionShape2D. Do you have a idea that could be a solution? Thank you in advance for this amazing course!
00Jun. 02, 2025
Regarding the challenge, this is my solution.silent-eelI'm not sure if it's correct, but it did achieve the expected result.
Additionally, I calculated the quantity and value of the gold coins
```gdscript
@icon("res://icons/icon_mob.svg")
class_name Mob extends Area2D
@export var health := 100.0 : set = set_health
@export var speed := 100.0
@export var coins := 1 : set = set_coins #The modified code
@export var coins_value := 1 : set = set_coins_value #The modified code
var tween : Tween = null
@onready var _health_bar: ProgressBar = %HealthBar
@onready var _bar_pivot: Node2D = %BarPivot
func _ready() -> void:
_health_bar.max_value = health
set_health(health)
func _physics_process(delta: float) -> void:
_bar_pivot.global_rotation = 0.0
func set_health(new_health):
health = maxf(0.0, new_health)
if _health_bar == null:
return
if tween != null:
tween.kill()
tween = create_tween()
tween.tween_property(_health_bar, "value", health, 0.2)
#if _health_bar != null:
# _health_bar.value = health
if health <= 0 :
tween.finished.connect(func():
die(true)
)
func take_damage(amount : float) -> void:
health -= amount
var damage_indicator : Node2D = preload("res://mobs/damage_indicator.tscn").instantiate()
get_tree().current_scene.add_child(damage_indicator)
damage_indicator.global_position = global_position
damage_indicator.display_amount(amount)
func set_coins(new_coins : int) -> void: #The modified code
coins = new_coins
func set_coins_value(new_coins_value : int) -> void:
coins_value = new_coins_value
func die(was_killed := false)-> void:
if was_killed == true:
for current_index in coins:
var coin : Node2D = preload("res://mobs/coin.tscn").instantiate()
get_tree().current_scene.add_child.call_deferred(coin)
coin.global_position = global_position
coin.mob_coins_value = coins_value #The modified code
queue_free()
```
```gdscript
class_name Coin extends Area2D
var tween : Tween = null
var mob_coins_value := 0 #The modified code
func _ready() -> void:
var random_angle := randf_range(0.0, 2.0 * PI)
var jump_distance := randf_range(40.0, 80.0)
var target_position := Vector2.from_angle(random_angle) * jump_distance + global_position
tween = create_tween()
tween.set_trans(Tween.TRANS_QUART).set_ease(Tween.EASE_OUT)
tween.tween_property(self, "global_position", target_position, 0.5)
func animate_to_ui():
if tween != null:
tween.kill()
var target_position : Vector2 = PlayerUI.get_coins_ui_position()
tween = create_tween()
tween.set_trans(Tween.TRANS_QUART).set_ease(Tween.EASE_OUT)
tween.tween_property(self, "global_position", target_position, 0.7)
tween.finished.connect(func() -> void:
PlayerUI.coins += mob_coins_value #The modified code
queue_free()
)
```20May. 20, 2025
Coin collector questionLucas PscheidtWhy did we create a node specific for collecting coins if we could just connect the mouse_entered signal directly in the coin script? Is there any particular advantage code-wise?10May. 03, 2025
Lesson Q&A
Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.