x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How do I set mouse boundaries?

I am doing a top down game and the character is following the cursor around the screen. The control handling isn't perfect, if the cursor touches one of the 4 walls (in the box room) the character will stop moving completely until the cursor is moved back to the floor...

What would be the easiest solution to this problem? I am fairly new with UE4 but I have tried adding a trigger box but I can not think of any nodes which can basically tell the cursor to stay within the box at all times.

I will leave a screenshot of the defualt cursor blueprints that come with the top down game template, I have only one gate as I did not require it for what I am doing but the rest of the nodes are all from the template.

Any advice is greatly appreciated.

Many thanks.

alt text alt text

Product Version: UE 4.13
Tags:
more ▼

asked Oct 19 '16 at 12:12 AM in Blueprint Scripting

avatar image

Tommow
15 13 17 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Well in C++, You do like this....

if (cursorlocation.Y < cameralocation.Y +1000.0f && cursorlocation.Y > cameralocation.Y - 1000.0f && cursorlocation.X < cameralocation.X +1000.0f && cursorlocation.X > cameralocation.X - 1000.0f )

{ movecursor(); }

more ▼

answered Oct 19 '16 at 01:01 AM

avatar image

A GUPTA
4.1k 102 46 618

avatar image Lexyth Oct 19 '16 at 02:24 AM

I'm gonna see if I can figure out how to translate this in BP. The main nodes are probably gonna be Branch - get Cursor location and equal to. I'll try to set up something.

avatar image Lexyth Oct 19 '16 at 03:53 AM

This could at least limit the movement of the green location in world space, but to limit your mouse you could only limit it on your screen and if I remember right you wanted to move the camera around. So the player could just move to the right to get outside the world with the mouse, but in this way you can limit the green thing to the bounds you want. You may have to change the lower variable to a different one, but not a simple =. This would cause it to stop only if it touches exactly the limit line, not over or under it.alt text

avatar image Lexyth Oct 20 '16 at 10:35 PM

I've editted it and it should work now by not getting the input if it is outside the boundaries on the world, but not on screen.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The real trick here is that there currently isn't a way to set the mouse cursor position from Blueprint built into UE4.

In general, the process is fairly simple:

  • Determine the X and Y limits for your mouse cursor; you'll need a minimum and maximum value for each. If you have a static camera, you can set values according to the room you're in, or if they're all the same size (like the original Zelda, or Binding of Isaac), you can use the same values all the time. If your camera moves, you're going to have to update the values based on that movement.

  • Determine the current position of the mouse. This one is easy, you can do that by getting a reference to the player controller, and calling GetMousePosition(), you'll get two floats - one for X and one for Y. Bear in mind that mouse coordinates are expressed in screen space, as X and Y coordinates on your screen, not within the game world. You can use DeprojectMousePositionToWorld from the PlayerController to get the mouse position in world coordinates, or you can convert your room position limits to screen coordinates.

  • Compare the current mouse position to your limits. Set branches for if X is greater than MaxX or less than MinX, and if Y is greater than MaxY or less then MinY.

  • If your mouse position is outside the limits, set the mouse position to be within the limites. (i.e., if X is greater than MaxX, set the X value to MaxX)

The last step is the real trick here. Within C++ you can get a reference to the Viewport from your player controller, and it has a method called "SetMouse"; but it's not currently exposed to BP. You can either edit the engine to expose this method, or otherwise write your own object to give you this method. Or you can install Rama's BP Library plugin that gives you the SetMouse functionality.

https://forums.unrealengine.com/showthread.php?3851-(39)-Rama-s-Extra-Blueprint-Nodes-for-You-as-a-Plugin-No-C-Required!

I think I'm going to go through the native SetMouse method and see if there's any reason Epic hasn't exposed it to BP, and if not I'll just do it myself and see if they accept the modification.

more ▼

answered Oct 19 '16 at 03:09 AM

avatar image

GigasightMedia
1.7k 43 12 61

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question