Any ideas of a smart way to show when an object exists outside of the camera view?

Godot Version



Let’s say the camera shows
x: 0 to1000
y: 0 to 1000

But the game area is larger than this.

So, imagine we have an object at global_position (-200, 400)

In this case, I’d want to show an indicator at the left edge of the camera view, at global_position (0, 400) showing that there is an object to the left of the camera.

Imagine there is another object at (500, -200).
That would mean we’d have another indicator at (500, 0).

Got any smart ideas on how to solve this in 2D?

I think you will find your answer in this video

1 Like

Thank you, that’s an excellent solution for 3D :smiley:
I should have mentioned this is 2D.

I found this excellent video though!

My solution is a lot simpler though:

class_name OffScreenIndicator extends Sprite2D

@onready var parent = get_parent()

func _process(delta):
	var camera_min =
	var camera_max =
	global_position.x = clamp(parent.global_position.x, camera_min.x, camera_max.x)
	global_position.y = clamp(parent.global_position.y, camera_min.y, camera_max.y)


So, I have a globals class called G:

class_name G extends Node

static var camera

And the camera looks something like this:

extends Camera2D

@onready var center = get_viewport().size / 2.0

func _enter_tree(): = self

func get_rect() -> Rect2:
	return Rect2(get_min(), get_max())

func get_min():
	return global_position - center
func get_max():
	return global_position + center
1 Like