Announcement

Collapse
No announcement yet.

Limit Mouse Cursor Position to certain area on viewport

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Limit Mouse Cursor Position to certain area on viewport

    Click image for larger version  Name:	UO20021020463826.jpg Views:	8 Size:	81.0 KB ID:	1719640



    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!
    Last edited by REMAN_OF_CYROD; 02-10-2020, 04:52 PM.

    #2
    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.

    Comment


      #3
      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.

      Comment


        #4
        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).
        Use a BP Clamp node...
        Last edited by UnrealEnterprise; 02-10-2020, 08:01 PM.

        Comment


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

          Comment


            #6
            Originally posted by Rev0verDrive View Post
            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.


            Originally posted by ClavosTech View Post

            Use a BP Clamp node...

            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.

            Click image for larger version  Name:	UO20021102051193.jpg Views:	0 Size:	319.0 KB ID:	1719753
            Last edited by REMAN_OF_CYROD; 02-10-2020, 09:10 PM.

            Comment


              #7
              Could you please be more specific?
              From Get Mouse Position 'X' drag a wire and search for Clamp (Float). Do the same by dragging off 'Y'. You'll need to supply Min / Max for both which will need to match the widget size (like the one above in cyan). Hook up both Clamps to Set Mouse Cursor (UE4 will automatically add a float to int converter, or you can keep the Truncate if you want). Is the widget size fixed? If so, just copy / paste the size into min / max. If its dynamic, then in order to get the widget size you'll need to cast into the widget to access its properties...

              Comment


                #8
                If cursor it's outside area, display no texture at all, or change it to some other random texture.
                Some cool unreal projects you may like!


                Developer of GOTA - Survivalism Gladiatorial game Buy the game google gladiators of the arena steam https://store.steampowered.com/app/7..._Of_The_Arena/

                Download the demo Download the demo
                external link Dropbox DropBox

                Become a c++ Professional now C++ Networking Tutorial

                Comment

                Working...
                X