Mouse interaction - method to avoid moving component pivot to mouse trace hit?

Hi, I am working from the Mouse Interaction level in the Content Examples project.

I know what I need to do but I am having trouble finding the blueprints to do it. Sorry I am little new to UE.

When you left click objects what happens is the components pivot moves to the location of the mouse. This results in the object “jumping” so that its pivot is now centered on the mouse. I aim to remove this behavior this way:

Get hit location - component pivot location = some vector.

get some vectors magnitude.

Add that magnitude as an offset to the actors location.

The goal is that when i click the actor, it doesnt move, and then when I move the mouse it follows and retains that offset.

Update:

I think i have successful made the correct offset. But it happens every frame so the ball shoots off screen like a bullet. Somehow I need to make this happen only once.

Hello! Can you share some more details - in what class is this logic implemented? Is it inside Tick body?

Hi Kehel, thanks for the response. I will show two images. The first shows the portion of the code that is working. Then I will show that portion of the code I’ve been working on.

And here is my “experimental” code.

I tried adding it to the vector in the Tick driven portion of the code just before the final SetActorLocation. But this caused the mesh to shoot off, I believe because it is adding that offset every frame.

THen I tried moving the code to the OnClicked portion, but I think I will need additional code because then the Tick part of the code overrides and causes weird behaviour.

I think what I need to do is say, “calculate this offset, add it to the mesh when clicked ONCE”. Of course it is simple to say but harder to write. I don’t have a strong math background so I might have my calculation wrong.

Also, this code is on the Actor that gets moved when it gets clicked. In this case it is a sphere mesh. The code is stripped down version of same you’ll find in the Content Examples project > Mouse Interaction Map

Here is the code that made it worked.