Guard: Hide the detection light at minimum scale - #2799
ricardolujan0501-glitch wants to merge 1 commit into
Conversation
manuq
left a comment
There was a problem hiding this comment.
This works! But it needs an explanation, and I wonder if the change is needed in the two places.
Also, please change the title and description to match our contributing criteria. Is very important that you explain your changes.
| # patrol path. | ||
| if patrol_path: | ||
| global_position = _patrol_point_position(0) | ||
| detection_area.get_node("Light").visible = detection_area_scale > 0.1 |
There was a problem hiding this comment.
Please explain why this is needed in the _ready function too. Isn't the one in the setter enough? And why inside the if patrol_path?
|
Thanks for the feedback! I tested the change and removed the Light2D visibility update from the setter, since the setter only needs to update the detection area's scale. I kept the Light2D visibility initialization in _ready(), where the detection area and its child nodes are ready. I also moved it outside the if patrol_path block because the visibility of the detection light is independent of whether the guard has a patrol path. |
manuq
left a comment
There was a problem hiding this comment.
Almost there! Again, please change the title to match our contributing criteria. Current title "Fix issue number" is too generic.
| detection_area_scale = new_value | ||
| if detection_area: | ||
| detection_area.scale = Vector2.ONE * detection_area_scale | ||
| detection_area.get_node("Light").visible = detection_area_scale > 0.1 |
There was a problem hiding this comment.
Please don't use get_node("Light"). Instead, give a unique name to the Light node that's in the same guard.tscn and reference it by its unique name from the script.
Alternatively, consider just hidding the whole detection_area node.
|
Play this branch at https://play.threadbare.game/branches/ricardolujan0501-glitch/main/. (This launches the game from the start, not directly at the change(s) in this pull request.) |
Have you tested it in the editor? These assumptions look wrong, are these thoughts yours? In #2799 (comment) I suggested the opposite. The setter should be enough, unless you can let me know why is needed in the |
|
Sorry for the confusion. I did not properly answer your question in my previous comment about why the line of code is not used only in the setter. I left it this way because it was not working as expected—the light cone was still appearing. The light needs to be updated when the Guard is initialized, which is why it was also placed in In the latest update, it was removed from the |
3cdb692 to
9a71b9c
Compare
|
Hello, first I force-reset my local branch to return to the initial commit (6bc3880) before making the modifications, because I felt that I had already changed too much during the previous tests. Regarding the issue, I created two functions to independently control the light and the detection area. The first one controls the light visibility when detection_area_scale reaches 0.1. The second one adjusts the detection area to keep the behavior consistent. The problem I found during testing was that when reducing the detection area to 0.1, the light disappeared correctly. However, when starting the scene, the light remained hidden while the detection area returned to a value of 1.0. This caused the enemy to detect the player even when the light was visually disabled. For this reason, I implemented both functions and call them from both the setter and _ready, so that the light and detection area states remain synchronized both when changing the value in the editor and when starting the scene. |
|
It looks like I commented without part of my comment, sorry:
|
| set(new_value): | ||
| detection_area_scale = new_value | ||
| if detection_area: | ||
| detection_area.scale = Vector2.ONE * detection_area_scale | ||
| _set_detection_area_scale() | ||
| _set_detection_light() |
There was a problem hiding this comment.
Instead of this, add a named setter:
@export_range(0.1, 5, 0.1, "or_greater", "or_less") var detection_area_scale: float = 1.0:
set = _set_detection_area_scale
Which would look like:
func _set_detection_area_scale(new_detection_area_scale: float) -> void:
detection_area_scale = new_detection_area_scale
if not is_node_ready():
return
if detection_area:
detection_area.scale = Vector2.ONE * detection_area_scale
_light.visible = detection_area_scale > 0.1
| _set_detection_area_scale() | ||
| _set_detection_light() |
There was a problem hiding this comment.
Instead, please call the named setter, like done with sprite_frames:
_set_sprite_frames(sprite_frames)
_set_detection_area_scale(detection_area_scale)
| if detection_area: | ||
| detection_area.scale = Vector2.ONE * detection_area_scale |
There was a problem hiding this comment.
This should be removed, since now the setter takes care of it.
|
|
||
| func _set_detection_area_scale() -> void: | ||
| if not is_node_ready(): | ||
| return | ||
| detection_area.scale = Vector2.ONE * detection_area_scale | ||
|
|
||
| func _set_detection_light() -> void: | ||
| if not is_node_ready(): | ||
| return | ||
| _light.visible = detection_area_scale > 0.1 |
There was a problem hiding this comment.
Please remove these in favor of the setter that I provided.

Guard: Hide the detection light at minimum scale
When detection_area_scale is set to its minimum value (0.1), the detection area is reduced to its minimum size. However, the Light2D used to visualize the detection area remains visible, causing a triangular light to appear over the guard instead of illuminating the ground correctly.
This change hides the detection Light2D when detection_area_scale is at its minimum value. The visibility is initialized in _ready(), after the guard's nodes are ready.
Resolves #2249