Object that follows mouse position. How to properly do it with BP?

I try to make simple BP where my actor object will follow mouse position. So I’ve done it with the simple BP:

but when I run it I get some “inverted” position of my actor. Why is it work like this?
I’ve recorded a video:

2 Likes

Try using “Get HitResult under Cursor”. This outputs a HitResult from which you can take the position on your map and make your actor move there.

Convert Mouse Location doesn’t project the location to the world and I generally had a lot of issues with that.

Cheers

I’ve already tried it :slight_smile: It also has strange behavior when I click at the same point two or more times: http://www.youtube.com/ - why it works like this?

Maybe that function has some bug?

I don’t actually understand what does exactly “Get HitResult Under Cursor” return?

A trace from your camera through your mouse onto the world. The HItResult outputs as always what was hit, where, with what normal, etc.

Since you use the visibility channel and your actor has visibility it will if you click twice hit the actor and place it there instead. The fix is fairly simple. You use the hit result under cursor for objects and only insert “WorldStatic” into object types. With that it will only look for things which you set to static. By default that’s the normal environment but not a pawn etc. This is set in the collision settings of your actors. Just make sure that everything you might move is set to “WorldDynamic” or something besides"WorldStatic".

Like that it will ignore your actor and properly hit where you clicked on the ground.

1 Like

It’s a different node.

“Get HitResult under Cursor by Objects”.

Sorry but I can’t find the setting. Where does it exactly place? I’m new to UE. I’ve been learning it just for 1 week.

You are using the mouse location node incorrectly. try something more like this to see how it would work:

It is unclear what you are truly attempting to do, and as OrchestralMusician stated you may actually want to use the get hit result but i wanted to post a example of the mouse location node you were using.

1 Like

by default the location returned will be right in front of the camera, the 500 is a distance away from the camera. The distance is based on what you feel is correct or the needs of the game.

What is the effect you want to happen? Do you want something to appear in front of the camera or on the ground based on the mouse location?

Thanks it works a little bit better! But it doesn’t place actor by the its clicked center. Why does it work like this? I supposed “500” should be calculated dynamically? If I set 850 instead 500 - it works a little bit better but only for some directions. Some directions work better with 500 and some of them better with 800, etc…

Yes, I want to place Actor (by center of it) on the ground based on the mouse location…

Then you want to go with what Erasio said then. Use the node: “Get Hit Result Under Cursor” This will return a hit result with a location along the ground/objects under the mouse. You can mask what objects get hit to be just your ground plane if you want by adding some custom collision channels.

I think this is what you are looking for:

All you need to do is change the break vectors to the direction you are facing (X,Y,Z) I don’t think +/- matter

Here is a text you you can copy-paste into the BP:
[Paste][2]

Also, you can subtract your first break vector float you chose by an amount if you want to use less of the viewport to move the mesh (by default it will use the viewport bounds for the movable units, so if the viewport is1920, the mesh will move -960 to 960 units)

To those who may come across this thread in the future. I found a number of issues with Convert Mouse Location to World Space and Get Hit Results Under Cursor by Channel. For most interactions of this nature (where you are trying to place a Building on the Floor for example) - try using Get Hit Results Under Cursor by Object.

Set your Object Trace to what you want to trace for (World Static in most use cases) and it will consistently return the floor location. The biggest issue with the other options that they will trace to the building you are trying to place (thereby defeating the point, you are trying to hit the floor, not what you just spawned) or move the object all over the screen and not the floor where you are trying to place it.

If you’re stuck like I was, give Get Hit Results Under Cursor by Object. a try and see if that suits your use case.

2 Likes

Nick, I know it is a long shot. But can you help me to built that mecanic in UE5? Please, I am hopeless!