I would try something like this (not tested):
extends Camera2D
var speed = 10
var vertical_movement_zone_size = 100
var horizontal_movement_zone_size = 100
var window_size = Vector2.ZERO
func _ready():
window_size = get_tree().root.size
func _process(delta):
# this will get the position in the viewport/game-window
var mouse_position = get_viewport().get_mouse_position()
# check vertical
if (mouse_position.y < vertical_movement_zone_size):
position.y += speed * delta
elif (mouse_position.y > window_size.y - vertical_movement_zone_size):
position.y -= speed * delta
# check horizontal
if (mouse_position.x < horizontal_movement_zone_size):
position.x += speed * delta
elif (mouse_position.x > window_size.x - horizontal_movement_zone_size):
position.x -= speed * delta
Then it should work with movement vertically and horizontally. The reason the other solution doesn't work is that the size of the window often isn't square, so parts of the circle get cut off. This solution instead checks to see if the mouse is around the edges of the window, instead of using a radius.
The only downside with the code as written above is that it will move at a constant speed, it won't get faster or slower as you move away from the zone. To fix this, I believe you just need to add the following:
# check vertical
if (mouse_position.y < vertical_movement_zone_size):
var mod_amount = 1.0 - (mouse_position.y / vertical_zone_size)
position.y += speed * mod_amount * delta
elif (mouse_position.y > window_size.y - vertical_movement_zone_size):
var mod_amount = 1.0 - ((mouse_position.y - (window_size.y - vertical_movement_zone_size)) / vertical_zone_size )
position.y -= speed * mod_amount * delta
# check horizontal
if (mouse_position.x < horizontal_movement_zone_size):
var mod_amount = 1.0 - (mouse_position.x / horizontal_zone_size)
position.x += speed * mod_amount * delta
elif (mouse_position.x > window_size.x - horizontal_movement_zone_size):
var mod_amount = 1.0 - ((mouse_position.x - (window_size.x - horizontal_movement_zone_size)) / horizontal_zone_size )
position.x -= speed * mod_amount * delta
But I haven't tested it and cannot say for sure whether it would work.
(Also: Moved to the 2D category)