You want it where the mouse does not move forward, or the character?
For the mouse, you can use warp_mouse
to teleport the mouse back inside the boarder area once it's outside of the border area. Figuring out whether the mouse is outside the border area could prove to difficult, and I currently cannot think of a great way to go about checking if the mouse is within a section/area of a scene or not. I would suggest looking into using a Rect2
and the contains_point
function.
If you do not want to move the player when the mouse is at the end of the area, then it's a little easier. One easy way to get around the player movement issue is to just place a bunch of StaticBody2D
nodes around the border so the player cannot move through that area.
Another way you could do it is place a Area2D
node with collision shapes around the area you want the player to be able to move. Then you can connect the body_exited
signal and then disable player movement when the player has exited, and then enable movement using the body_entered
signal.