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
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:
Something to rotate whenever you move the mouse.
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?
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!
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:
use WinKey+Shift+S to open the snip tool, don’t use a full screen shot.
Include as much code as possible. Three nodes in the middle doesn’t explain much!
Make sure the text is readable.
Get some code shots and I think we can figure this out!
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.
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:
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.
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!
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.
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!
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.
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: