I have an overhead top down camera setup for my game and i use the mouse to scroll it, but when the camera reaches its set limits (left : -1000, Top : -500, right: 3000, bottom : 2500) it goes beyond it but the viewport doesn't, how do i clamp the camera to only move within the set limits and not beyond, thanks in advance! (camera code below)
extends Camera2D
var is_panning = true;
var cam_spd = 10
onready var editor = get_node("/root/World/Cam_container")
onready var editor_cam = editor.get_node("Camera2D")
onready var maptype = get_node("/root/World/Compositemaps").maptype
func _positioner():
if maptype == 'dungeonmap1':
position = Vector2(152,64)
elif maptype == 'dungeonmap2':
position = Vector2(1592,1360)
elif maptype == 'dungeonmap3':
position = Vector2(1680,144)
elif maptype == 'dungeonmap4':
position = Vector2(1432,1576)
func _ready():
_positioner()
editor_cam.current = true
func _process(_delta):
move_editor()
is_panning = Input.is_action_pressed("mb_left")
pass
func move_editor():
if Input.is_action_pressed("w"):
editor.global_position.y -= cam_spd
if Input.is_action_pressed("a"):
editor.global_position.x -= cam_spd
if Input.is_action_pressed("s"):
editor.global_position.y += cam_spd
if Input.is_action_pressed("d"):
editor.global_position.x += cam_spd
pass
func _unhandled_input(event):
if(event is InputEventMouseButton):
if(event.is_pressed()):
if(event.button_index == BUTTON_WHEEL_UP):
editor_cam.zoom += Vector2(0.1,0.1)
if(event.button_index == BUTTON_WHEEL_DOWN):
editor_cam.zoom += Vector2(0.1,0.1)
if(event is InputEventMouseMotion):
if(is_panning):
editor.global_position -= event.relative * editor_cam.zoom
pass
video of what happens : https://streamable.com/t24jby