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.
Just sharing my tween animation for mob's die() functionLucas Pscheidt```gdscript
func die():
if not is_alive:
return
is_alive = false
enemy_die_sound.play()
var die_sound_time:= enemy_die_sound.stream.get_length()
await get_tree().create_timer(die_sound_time/3).timeout
var tween := create_tween()
tween.tween_property(sword_sprite, "global_position:y", global_position.y+35, die_sound_time/3).set_ease(Tween.EASE_IN)
tween.parallel().tween_property(sword_sprite, "global_rotation_degrees", global_rotation_degrees + [-3.5,-3,-2,-1.5, 1.5,2,3,3.5].pick_random() * 5, 0.1).set_ease(Tween.EASE_IN)
tween.parallel().tween_property(shadow, "scale", shadow.scale * 1.25 , die_sound_time/2).set_ease(Tween.EASE_IN)
tween.tween_property(self, "modulate:a", 0, 1).set_ease(Tween.EASE_IN)
tween.finished.connect(queue_free)
```11Jan. 03, 2025
I get setter functions now!miserly-dugongI thought it would be useful for the teachers to know that I didn't understand the use case of setter functions until this section, it's so much clearer now that I know it's just a function running every time a variable is changed. Thank you!10Feb. 19, 2025
Question about set = set_healtholiver_gzzHey there, is there a lesson where we saw the logic on the `set = set_health` line of code that follows the **health variable?**
**`var health := 100: set = set_health`**
I do remember, using the `set_health()` function, but not like this.
The way is suggested in this lesson, I think it's simpler and cleaner.
20Feb. 04, 2025
The method to force update physics calculation?DMKHi, this is not a question specific to this lesson, but I'm finding that method that was in some lesson, that lets you force update the physics calculation, so that I can get the overlapping bodies of an area2d the same frame it's added to the tree.
I'm pretty sure it was called something like force_update, but I don't know where it is.
Or maybe I'm just hallucinating, and it never existed. If so, can you tell me how that would be implemented?20Jan. 21, 2025
Handling the mob's death soundHardRockFor this optional task one of the hints is that we should connect the the `finished` signal of the AudioStreamPlayer to `queue_free()`. However, I didn't want to do this, since it seemed to me that this would complicate things by duplicating the places `queue_free()` is called from (since one call would remain in the `die()` function as well, in case there is an enemy that doesn't have a death sound). Furthermore, it didn't really make sense to me that it should be the responsibility of an audio playback to delete an enemy. So instead I await the finished signal in the die() function itself like this:
> func die() -> void:
> set_physics_process(false)
> audio_stream_player.play()
> await audio_stream_player.finished
> queue_free()
Is there anything wrong with this approach? It's likely I haven't considered all scenarios that could crop up in a more complex project, but it seemed to me that this way the `die()` function would remain more easily extensible, since I wouldn't need to make sure that playing the death sound would be the last thing I do in it, like if I'd follow the challenge hint.10Jan. 05, 2025
Mob Health setterram876Hello. I wrote a code for a mob where I write a health setter like this (my initial code without checking for the existence of animation_player).
```gdscript
func set_health(new_health: int) -> void:
health = new_health
if health <= 0:
die()
else:
if animation_player:
animation_player.play("hurt")
_hurt_sound.play()
```
There I play an animation depending on the change in the amount of health. Everything was working correctly. But in the lesson where we work with pickup, I decided to change the health of the mob at the level through the editor. As a result, I get the error that animation_player and _hurt_sound cannot be started, since animation_player and _hurt_sound are not yet available when calling the setter. I added a check for the existence of animation_player to the setter and there is no error anymore. What would be the right thing to do in this situation?20Dec. 30, 2024
How can I know if a node is still in the tree?◆ LPUsing `if body is_in_tree():` or `if body is_visible in_tree():` gives error about expected ":" after "if" condition. Am I missing something?30Dec. 18, 2024
Missing kill.wav sound in mobs directoryRuben TeijeiroI think the kill.wav sound is in the common/sounds folder and not in the mobs folder. At least I couldn't find it.10Dec. 06, 2024
error _hit_boxCelsmissing hit_box ensure it is included in the @onready var. hit_box it's an important feature for melee mobs10Dec. 04, 2024
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.