# Get Mouse Position on Viewport (Wrong axis?)

Hello Everyone,

I am a bit confused about this function. My 2D game uses the X (right and left) and Z (up and down) axes. However, when I use this function, it is based on the X and Y axes. Is there a way to fix this? That said, when I move my mouse cursor around numbers change for both X and Y when I use the printstring function, but I’m not sure why when the Y axis is not even used.

Thanks

Hi man,

the viewport is like a piece of paper, on wich you move the moouse,
You can move the mouse on paper on left-right (X) and up-down (Y), but you cant go go inside the paper or away from paper.
So you can define the mouse position using only X,Y, in this “Plane”

What you see inside the viewport, is a 3D space
Where any position of the mouse X,Y, have an infinite possible positions in Z.

So when you are interested in getting where the mouse is in the “view” you can use the get mouse position on viewport.
If you want to know the point in space, under the mouse (like if you want to click on a cube you have in the scene, and get the distance or the object)
you need to convert these 2 space coordinated in 3D,
as said before there are infinite position in Z, so usually we use raycast to get the first hit with a solid object, and use that as “good 3D converted”.
for example using “Convert mouse location to worldspace”

If your game and mouse dont match in orientation,
Like up and down , because the screen have Y, and the world have Z
you can always break the coordinate released by the get mouse position
And this will give you 2 floats, X Y
You can plug Y in any other coorindate sistem and use it like is a Z.

Here "Get Mouse Position on Viewport" - Blueprint Visual Scripting - Unreal Engine Forums
you can see how someone break the 2D coordinates and make a new .
To break the pin right click and choose break.

1 Like