About Question 1, I figured the smooth setting was the issue. Removing the smooth setting removes the acceleration/deceleration effect.
For Question 2 I found a workaround with code, but I am not a big fan of it. I feel the limits should also be enforced for the camera position by default.
So, first I get the current viewport size, the dimensions of the camera:
onready var viewportSize = get_viewport_rect().size
Then I wrote a function that checks if a point is within the camera limits:
func isWithinCameraBounds(point: Vector2) -> bool:
var vph = viewportSize.x / 2
var vpv = viewportSize.y / 2
return point.x + vph < limit_right && point.x - vph > limit_left && point.y - vpv > limit_top && point.y + vpv< limit_bottom
and updated my move code:
func _process(delta) -> void:
var input_vector = Vector2.ZERO;
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
var _pos = position
if input_vector != Vector2.ZERO:
var distance = input_vector * keyboardSpeed
var target = position + distance
_pos = position.move_toward(target, keyboardSpeed * delta)
if isWithinCameraBounds(_pos):
position = _pos