How do I take the mouse's moving position and convert it to world position?

How do I take the mouse’s moving position and convert it to world position? I want to change the mouse movement to world position. I tried this with some nodes but I was not successful. I want to get the position of the mouse not only when I click but also when it moves. I will give this position a collision
The code I used for the 1st video

The code I used for the 2st video

These codes only work if I click, but I want them to work if I move.


Hey @MAA7!

Unfortunately, there’s not really enough to go on to answer your question! You are saying you “want it to rotate without clicking”- but we don’t really know what “it” is. The camera? The player? A selected pawn?

I get that you want a collision to follow the cursor. But it seems like you want:

  1. Something to rotate whenever you move the mouse.
  2. For there to be a collision volume under the mouse. Is this top down? do you want this to be at a ground level, if so?
  3. I’m not really understanding what you need world position for the mouse, the mouse lives in 2D on your viewport (X and Y, no Z) so it doesn’t have a world position.

Can you clear things up a bit? Then we’ll see if we can help more easily!

1 Like

I was able to place a sphere collision under my mouse cursor when I clicked the mouse in the game. But I want to do this only when the mouse is moving, not when clicked. just when i click the sphere collision is placed where my mouse cursor is. Did I explain?

One thing you can try, is spawning the sphere collision on BeginPlay, and then move the collision on event tick- but I don’t know how you’re going about placing the sphere collision so I can’t give any specifics. Do you think you could bring some pictures?

Things to keep in mind when taking blueprint screenshots:

  1. use WinKey+Shift+S to open the snip tool, don’t use a full screen shot.
  2. Include as much code as possible. Three nodes in the middle doesn’t explain much!
  3. Make sure the text is readable.

Get some code shots and I think we can figure this out! :slight_smile:

1 Like

I updated the question

I know there is a solution to this, maybe it’s something very simple but I couldn’t do it.

Okay, awesome!

So first things first: You can put the trace on tick and move the sphere to that location.

Make a new variable called “Old Mouse Position” and set it with this on “begin play”. This is how we’ll set it originally, you’ll see why in a moment. Use the “World Location” off of that and save that vector.
image

Next, on tick, use that same bit of code, and check if your “Old Mouse Position” variable == the World Location output here. If it IS NOT THE SAME, that means you moved! You make a branch there, and off of the false branch, SET “Old Mouse Position” using the one you got here on tick, and run the rest of your code here:

Let us know if anything is too confusing or you need any additional help!

1 Like

I actually read what you wrote 10-15 times but I couldn’t do anything. When I use get mouse posiiton on viewport, it is set to a place away from the cursor, as in the first video. But other than that, another node does not give the position of the mouse only when it moves. Can you explain with a visual what needs to be done, I’m new to the unreal engine. :smiley:

Here, I made a quick mock-up for you!
You can have other things on begin play and tick, just make sure you don’t block them off with other branches or anything! :slight_smile:

image

I’m not entirely sure it will work based on the fact that I don’t have your project, but I’m fairly confident it should!

I did exactly as you said. But the sphere collision is still not right under the mouse cursor. When I do not press the left mouse button and just move it around, I move the sphere collision with the mouse cursor, this is very nice, this is what I want. There’s only one thing left: the sphere collision should be exactly under the mouse cursor, not near or far from it.

@Mind-Brain
I know there is an easy way to do this, but how?

Hey @MAA7! Sorry for the late reply!

Can you test it… in full screen? I think I know what’s going on. If you test it in full screen and it still doesn’t act right, what I had in mind won’t work. I’m thinking it’s getting screen space of your monitor for this. Give that a try and I’ll work on a solution if the full screen fixes it!

1 Like



Ah I see a couple of issues.
This needs to be set again afterwards, or it will always run constantly. If this messes your mouse movement up, just change it back.

We need to add the world direction x 10000 to the original world location for the end point.

image

Okay. Give that a try, that should make it exactly where the mouse is.

1 Like

I think I understood what you said correctly, but this didn’t work either, it’s not in the same place.

@MAA7 Oh no, that was absolutely my mistake! The second picture was the wrong one, I edited it and it should have the right picture there now!

The other part you added was just good practice to make sure you’re not overloading tick, and you did that correctly! :slight_smile:

1 Like

This doesn’t work, man. Cursor and sphere collision are still not in the same place

I’ve got one last thing before I’m going to have to start digging… I’m still thinking it’s based around the “Get Mouse Position in Viewport” node.

Try taking that and the “Convert Screen Location to world Space” node out, and just using “Convert Mouse Location to World Space” in their place.

1 Like

Using a physics handle to grab and hold an object, this is how i do it, it’s very similar to your way but less roundabout, it is very accurate. Also here’s an alternate way:

The ‘trace start’ will be the cursor’s position, trace result location will be what was clicked on.

If you want it to update constantly instead of only when you are clicking, the simplest way is to just run it on event tick.

1 Like

What is grab distance?