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.
I did a LmabdaRewardingChimpSo I decided to put the rocket damage directly in a lambda and the mob was getting one shoted. After printing in the mob script the damage taken and making the mob's health 1000. The rocket was 3 shoting it and calling its take_damage many times on a single impact. Not only that but the number of calls were wramping up with each shot. Can you explane this interaction.
code ref:
```gdscript
@icon("res://icons/icon_rocket.svg")
class_name Rocket extends Area2D
@export var rocket_speed := 400.0
@export var max_distance := 1000.0
@export var rocket_damage := 20.0
var _distance_travelled := 0.0
func _init() -> void:
#makes the rocket non detectable
monitorable = false
z_as_relative = false
# makes the rocket move if we scale up the rocet the
# transform.x will not be a normalized vector so it woud not work
func _physics_process(delta: float) -> void:
_distance_travelled = rocket_speed * delta
position += transform.x * _distance_travelled
area_entered.connect(func(body: Area2D) -> void:
if body is Mob:
body.take_damage(rocket_damage)
_explode()
)
if max_distance < _distance_travelled:
_explode()
func _explode() -> void:
queue_free()
```30Apr. 26, 2025
Tween questionjonathajHello! I was trying to use Tween.new() to create a tween in the set_health function, but was seeing that the health bar value was not updating. I checked the documentation and all it said was "**Tween**s created manually (i.e. by using `Tween.new()`) are invalid and can't be used for tweening values.". I was wondering why this is for tweens. We use the .new() for other objects and that seems to work fine, but for tweens we need to use create_tween. Is there a specific reason for tweens to have it this way?20Apr. 23, 2025
Solution for the Tween challengeKetanCouldn't come up with a better way to do it while using the tween_property method, I'm still trying to wrap my head around tween_method
```gdscript
func set_health(new_health: float) -> void:
health = maxf(0.0, new_health)
if _health_bar != null and health >= 100:
_health_bar.value = health
if _tween != null:
_tween.kill()
_tween = create_tween()
_tween.tween_property(_health_bar, "value", health, 0.5)
if health <= 0.0:
_die()
```40Apr. 23, 2025
Tween doesn't work with .stop() approachdim-pantherHey. So i was wondering if i can just initialize a tween once and use it all the time for the tweening, but there are some issues and i guess insights from this:
1. It doesnt work - the health bar doesnt update.
2. I guess allocating a tween for every enemy is not needed, as there is no guarantee that every mob is damaged as soon as it appears. But maybe could save some performance when there is a chain-like attack?
Anyways i rewrote it to create and/or kill the previous tween and it works properly
```gdscript
@onready var health_bar_tween := create_tween()
func _set_health_bar_value(new_value: float):
if (health_bar == null): return
if health_bar_tween.is_running(): health_bar_tween.stop()
health_bar_tween.tween_property(health_bar, "value", new_value, 0.5)
```10Apr. 10, 2025
Tween challengepetty-hareHello ! In the challenge you will kill the tween if it was running but i've tried it without and it seems to work preperly, do we really need it ?70Mar. 07, 2025
Distortion of the HealthBar at full screenram876Hello! When I start the mob scene, if the game is in fullscreen mode, the healthbar gets distorted and spoils the picture. I tried to put it in the settings Rendering -> Textures -> Default Texture Filter ->Nearest. The picture became clearer, but the distortions remained. Is there anything else I can do?100Feb. 17, 2025
Another workaround for rezising the health barmilk_manI only get the error message `parent_rect_size.x == 0.0" is true` and thus not able to resize the ProgressBar, if its Anchor symbol is turned on (blue). So another workaround would be to just turn it off and then you can resize just fine20Feb. 14, 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.