Moving an object by analyzing the mouse's movements

Godot Version



Hello there, I’m currently making a game that uses a certain mechanic which is moving an object, based on the mouse movements, so when the mouse moves x-1 y7 it reproduces that movement on the object. But I had one struggle with it : my code below

extends CharacterBody2D

var x_pos = 0
var y_pos = 0

func _input(event):
	if event is InputEventMouseMotion:
		x_pos = event.relative.x
		y_pos = event.relative.y
		position.x += x_pos
		position.y += y_pos

Basically what the code is doing, is taking the movements of the mouse as said above but when I want to make it go to the right but the border blocks the mouse, it doesnt move :

So, if anyone could provide me more information about it such as if it has already been talked about somewhere or if theres a function for that I would appreciate a lot ^^ thanks for any responses !