I would like to allow the player to move the camera as he puts the mouse on the edges of the screen, like in Age of Empires or League of Legends, but I’m succesless.
For now I have made a controllable and visible cursor, but I am currently stuck.
In generall you would need to track the Mouseposition (that’s the easy part) and move the camera based on this position.
Since you can get the Viewportsize, i guess you could make something like this:
- If the MousePositionY is less than 50 (pixel), move the camera in top direction.
- If the MousePositionY is greater than ViewportSizeY - 50, move the camera in bottom direction.
- If the MousePositionX is less than 50 (pixel), move the camera in left direction.
- If the MousePostionX is greater than ViewportSizeX - 50, move the camera in right direction.
This should keep in mind different ViewportSizes and should be done easily.
I don’t know exactly how you would move the camera alone, because i haven’t done
something like this till now, but above is the basic idea i have for RTS Camera Movement.
Thank you! Had the same idea and got it to work
Thanks for this. Found this on google and it worked like a charm. Slightly unrelated, but I wonder if there’s an easy way to have the camera movement more “gradual” or “slower” when we are on the edge of the movement area of your screen. Like, the closer you are to the edge, the faster you go, but if you’re right on the boundary of no movement and beginning of movement, you go slow. Anybody have any ideas on that?
Ah! Yes, that makes perfect sense. Thank you very much!! I had something sort of like that but I didn’t consider map range clamped.
Well, if we stick to the 50 pixel example from above, you know that, from the inner edge to the outer, it’s 50 pixel. So when you track your mouse and compare it, you know how far the mouse is towards the outer edge. You might need to change the equation a bit for each edge.
For the top direction it would be “ViewportSizeY - MousePositionY”. That should be 50 to 0 (inner to outer edge.
Now you simply do a “MapRangeClamped”. Where you go from 50 to 0 for the input and MinSpeed to MaxSpeed for the output. (which are the lowest two input pins on the node).