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.
For some reason my rocket explodes multiple times and my explosions don't hit anythingBrain Siege GameworksSpecifically, my rockets explode several times despite my rocket having monitoring set to false by call deferred and my explosions don't get any overlapping areas when instanced, despite the call of that function being after awaiting the next physics frame.
Homing Rocket:
`func explode() -> void:`
`...`
`get_tree().current_scene.add_child.call_deferred(explosion)`
`explosion.global_position = global_position`
`set_deferred("monitoring", false)`
`set_physics_process(false)`
Explode:
`func _ready() -> void:`
`.`..
`await get_tree().physics_frame #wait for the physics to update.`
`print(get_overlapping_areas())`
`for area: Area2D in get_overlapping_areas():`
`if area is Mob:`
`var final_damage = damage`00May. 09, 2025
Just a reminder: be careful to not confund physics_frame with process_frame!Lucas PscheidtJust writing this down 'cause if I ran into this (since I'm used to using `process_frame` and had never used `physics_frame`), I imagine others might too. The explosion won't deal damage if you use `await get_tree().process_frame`, learned that the hard way and spent like 20 minutes trying to figure out why it was bugging out lol10May. 09, 2025
More you can do with the explosionBrain Siege GameworksThe explosion provided does flat damage to everything in it's area. However I've tried to make it more interesting by making it do damage proportional to the distance.
There's probably more that can be done with it, it probably works though.
```gdscript
extends Area2D
var damage := 10.0
@export_range(0, 1) var falloff_strength := 0.5
@onready var animated_sprite_2d: AnimatedSprite2D = %AnimatedSprite2D
@onready var collision_shape_2d: CollisionShape2D = %CollisionShape2D
@onready var circle_shape_2d: CircleShape2D = collision_shape_2d.shape
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
animated_sprite_2d.play()
animated_sprite_2d.animation_finished.connect(queue_free)
await get_tree().physics_frame #wait for the physics to update.
for area: Area2D in get_overlapping_areas():
if area is Mob:
var final_damage = damage
var distance = global_position.distance_to(area.global_position)
var aoe_radius = circle_shape_2d.radius
var multiplier = (distance/aoe_radius)
final_damage = final_damage - (roundi(final_damage * multiplier) * falloff_strength)
area.take_damage(final_damage)
```10May. 08, 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.