Godot Version
v4.3.stable.official [77dcf97d8]
Question
I’m trying to have an offscreen indicator that shows the player where to go find the axe they threw. But I’m having trouble with it. The offscreen indicator either appears in the incorrect spot and doesn’t move or simply disappears with the axe.
Can anyone help me figure out what I’m doing wrong or link me to an answer for reference? I’ve looked around but couldn’t find anything.
Here’s my code:
extends Node2D
@export var tracked_object: VisibleOnScreenNotifier2D # Currently unused, but feel free to utilize it if needed
@onready var sprite = $TextureProgressBar
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var canvas = get_canvas_transform()
var top_left = -canvas.origin / canvas.get_scale()
var size = get_viewport_rect().size / canvas.get_scale()
set_marker_position(Rect2(top_left, size))
func set_marker_position(bounds: Rect2):
sprite.global_position.x = clamp(global_position.x, bounds.position.x, bounds.end.x)
sprite.global_position.x = clamp(global_position.y, bounds.position.y, bounds.end.y)
if bounds.has_point(global_position):
hide()
else:
show()
print(global_position)
Here are screenshots of my scene docks: