overlaping ranges of slowdown turrets


When the ranges of slowdown turrets overlap, mob speed is decreased correctly, but the "tint" is removed when leaving the first range, rather than last range of slowdown turret.

I understand the problem and why is it happening. I'm just thinking of how I would approach it to fix it.

a) keep a state "on mob", tracking the count of nearby slowdown turrets. Eg increase the count when entering, decrease when leaving the range. It seems that scene "A" cannot just willy-nilly add new properties to scene "B". Scene B would have to be cooperating on tracking the state.

b) keep a global list of all slowdown turrets and list of their neighbor mobs. For every enter/exit event, search the mob (from body parameter) in all other lists to get the count. The only way I can think of how to iterate over all instances of a scene, if they are all under the same parent.

c) is there another elegant solution ?

Which solution would experienced Godot programmer choose ?

  • Nathan Lovato replied

    The simplest way to handle this, to me, would be to move the detection code to the enemy itself: add a small Area2D to the enemy scene, connect its area_entered and area_exited signals,  and when an area exits, check for remaining overlapping towers using Area2D.get_overlapping_areas().

    This removes the need for keeping a list of all the towers and the map. It is the simplest solution I can think of.

    1 love