Any other solution other than convert mouse screen to world space?

Working on a 2d game, and it’s come to our attention that we have a major hurdle to overcome. Because we don’t use orthographic, the camera is placed very far from the actor, about 60000 units at an fov of 5. Because it is so far, world projection is absolutely broken, as it doesn’t seem to touch the far assets. And when it does however, that’s when the camera is much closer. But then comes the next issue, the trace is pinned to a certain location of the map meaning if I move, the “screen” hasn’t moved.

So it’s clear that mouse screen position to world space is unreliable. And I’m wondering if there are better methods, or if there is a possible solution to resolving such an issue.

My suspicions are probably towards the game being on the XZ plane being the possible culprit. Or it’s just straight up too far and the engine doesn’t allow me to trace that far.
The result -

There is something missing here. You don’t talk about any function that would read mouse coordinates or try to unproject the value in your problem description.
What code are you calling? What do you pass into it? What do you expect it to return? What is it returning?

There is nothing in particular that would cause the built-in mouse projection or hit-testing trace functions to fail just because you’re 600,000 units out that I can think of, so making sure that the functions and arguments are right, first, would be step 1.

Note that if you use a cinecamera, or some other display mode that puts letterboxing bars on the screen, getting the right mouse position to use is not entirely trivial, some math is required as far as I can tell.

Forgotten to send that somehow, here you go then.
For someone posted by anonymous | blueprintUE | PasteBin For Unreal Engine

Two things I notice:

  1. Your ActorLocation doesn’t have an actor input, so I think it will trace from 0,0,0? You should get the currently viewing camera as the actor you take the location from. You can get this from the player controller.

  2. You only cast the ray 1000 units forward (the multiply by 1000) so of course you won’t find anything 60000 units away! Crank that thing up to 1000000.

When you think that you’re having trouble with ray casts, turning on the debug draw visualization is very helpful. Of course, if you correctly cast from the center of the camera and outwards, the ray will exactly follow the camera, so it will be infinitely narrow. But if you get it wrong, it will show up nice and visible (at least when you’re looking in the direction where the “wrong” places it.)

Actually, I don’t understand what actor you’re trying to cast a ray from. Are you expecting to start at the null/empty actor, and then casting to a position 1000 units in front of the near clip plane? Traditionally, mouse ray picking will start at the camera center, and trace forward for X amount of distance into the scene, and then figure out which actor got hit by that trace. If you’re trying to do something else, please explain in more detail what you expect to happen.

2 Likes

I managed to find this out before you came in! Apparently if I did crank it, would actually go past!. At least in my case. because my camera was at a fixed distance, I implied multiplied the camera’s distance and the world direction.