Limit Mouse Cursor Position to certain area on viewport

Hello,

i would like to restrict the mouse cursor to a certain area of the screen, like shown in this example picture. It´s important that the restricted area always stays relative to the full viewport (no matter how small the viewport window is resized or whether it´s in fullscreen mode).

  • the mouse cursor should be moveable within the restricted (in this case TEAL) area only
  • once the mouse cursor gets to the edge of this area, it shouldn´t be able to move outside the area, but stay at the edge

I tried out several methods with unsatisfying results, i hope your expertise will open my eyes to something obvious that i´ll keep missing for some reason.

Thank you in advance!

A bit more detail is needed. What’s the intended purpose?

I’m assuming you want to limit the Pitch and Yaw of the camera. When it reaches the left/right edges of your rectangle area you want the Pawn to rotate. For pitch you simply want it to stop moving the camera vertically.

1 Like

The player should be able to aim (using the crosshair, controlled by the mouse) at things within a particular area on the viewport. The crosshair should stop at the edge of that (in this case TEAL) area and not go beyond that.

If you click the left mouse button a shot will be fired from the gun at the current crosshair position using Line Trace. That works well, but i just can´t find a satisfying solution for keeping the mouse cursor within a limited area on the viewport (no matter the actual viewport size = small window /fullscreen at different resolutions).

The camera or character movement aren´t affected.

You have to limit rotation and pitch in BP. Take a look at Aim Offset tutorials.

Thanks for the suggestion, but that´s not quite what i´m after.

I merely want to limit the movement area of the mouse cursor to a specific area on the viewport, don´t mind the character or camera.

Could you please be more specific?


At the moment i´m using a blueprint script that resets the mouse cursor to a position near the edge (of that teal area) once the mouse cursor leaves a certain area (that teal area in the very first picture). As i said before, it does the job but i´m not happy with it, for there must be a much simpler and cleaner solution to this, which i apparently can´t see

Oh btw, it´s a 2D game.

If cursor it’s outside area, display no texture at all, or change it to some other random texture.

Did u find out how to do it?