Yet another get world coordinates from mouse screen issue

Greetings. I feel I am at my wit’s end with this trivial matter.

What I am ultimately aiming to do is a city builder. There is a grid space starting at 0, 0 and ending at 10,000 10,000. Consider X and Y to be the place where I want my mouse pointer to be raycast on and represents the ground.

What I have tried is making a trace channel, then added a block volume and set everything on ignore except that channel.

Then I used a “Get hit result under cursor by channel” to get the location. What i get is an x and y value that differ by 0.1 or multiplies of. I played with settings a lot and somehow managed to get my result but it jittered a lot with Z = 0 (the ideal situation) and a x, y an z = 64 case. It was too easy to reproduce to ignore it and the result is horrible.

I also tried with “Convert mouse location to world space” but a dead end as well.

What I request is a clean and working answer. I have seen this stack exchange module filled with this question with partial or no answers. Thank you!

looks around for Steve Allison

Hey virusescu,

How were you using Convert Mouse Location to World Space? It sounds like everything you’ve tried so far should have worked–I don’t know offhand what would cause your results to be that far off.

Would you mind posting screenshots of your blueprint setup(s) where you are doing these calls?

-Steve

@Steve_Allison :diamonds::diamonds: I have noticed the cube is going in the same place as the current camera. When debugging I don’t have a camera on the scene, I use the option in the Play to use the current location. I will make some screenshots after work. I could also provided a zip of the project.

@Steve Allison :diamonds::diamonds: Here is a small project. The code for the raycast is in GameController. There should be an InputTrace custom channel and the collision plane has inside a box that blocks ONLY that custom trace channel. Dropbox - Error

Hey virusescu,

Here is a setup you could try out (not sure how you had Convert Mouse Location to World Space before) that should get you a Location and Direction for your Mouse which you can turn into a Line Trace by Channel using your custom Trace channel.

Give it a try and let us know if it works for what you’re trying to accomplish.

-Steve

I haven’t tested it out yet, but I found a function in PlayerController that will greatly simplify what you’re doing.

FVector WhereAmI;
FVector WhereAmIPointing;
DeprojectMousePositionToWorld( WhereAmI, WhereAmIPointing);

The function takes references, not values, so the FVectors you pass in end up giving you 1) the location of your mouse pointer and 2) the forward direction of your mouse pointer based on the direction of your view.

You’ll want to use this info with a ray trace.

I found a function in PlayerController that will greatly simplify what you’re doing.

FVector WhereAmI;
FVector WhereAmIPointing;
DeprojectMousePositionToWorld( WhereAmI, WhereAmIPointing);

The function takes references, not values, so the FVectors you pass in end up giving you 1) the location of your mouse pointer and 2) the forward direction of your mouse pointer based on the direction of your view.

You’ll want to use this info with a ray trace.

I found convert mouse location to world space puts your location to a 900 z value for some reason for a top down view. Maybe this will help you guys solve this.