Godot Version
Godot 4.5
Question
I am making a grand strategy esque game and I am using a 3D Camera in order to look at my 2D Map. In order to do this, I have placed the 2D Map into a SubViewport in the 3D scene (First photo).
I have a basic camera script working, and I’ve figured out how to limit its movement at particular axes like so:
var upper_x_limit = 20
var lower_x_limit = -20func _process(delta):
if global_position.x > upper_x_limit:
global_translate(Vector3(upper_x_limit - global_position.x,0,0))
elif global_position.x < lower_x_limit:
global_translate(Vector3(lower_x_limit - global_position.x,0,0))
However, because there is the ability to zoom and also to rotate the camera, it doesn’t seem possible for me to accurately set out hard limits for where the camera can go.
What I want to prevent is the camera being able to see the empty space outside of the map, like in photo 2. What is the proper way to create a system that prevents this?
Most grand strategy games do so, such as Europa Universalis series, which has a 3D camera which can move, zoom, pan and tilt but is still prevented from looking outside of the map.