I have a 2D Scene with multiple TileMapLayers, and have created a script to allow the user to drag the Camera2D whilst holding the right mouse button:
extends Camera2D
var dragging = false
var last_mouse_position = Vector2()
func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_RIGHT:
dragging = event.pressed
if dragging:
last_mouse_position = event.position
elif event is InputEventMouseMotion and dragging:
var delta = event.position - last_mouse_position
position -= delta
last_mouse_position = event.position
I want to limit the movement of the camera so it doesn’t move past any edge of the base TileMapLayer so the TileMapLayers are always in view of the camera, but I am struggling to figure out how to work this. What would be a good way to achieve this?