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();
}
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();
}
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.
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.
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:
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.
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.
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.
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.