Return value for mouse position on viewport

I am trying to understand this drag function and don’t understand why vector B is being subtracted from vector A. Could anyone explain why vector B is being subtracted from vector A ?

To offset the coordinates for some reason, probably to position widget in proper position of cursor or to make widget follow cursor in perticilar offset. I would inspect how widgets are positioned in that widget blueprint and how it is displayed on screen because it is related to that.

Render Transform moves the widget on the screen without physically moving it in widget coordinates, Translate means applying offset from original position, so it needs to substaction from original position to properly apply the offset. This is what probably what this code do.

Hi thanks for your reply, I am looking into ways of linking the movement of the screen to widget coordinates.

I am developing a 2d game in which the user drags and drops a sword. I want the sword position to be the same as the mouse position when dropped . At the moment, when I release the mouse, the sword tip moves to the mouse position. The tip of the sword moves to the mouse position when I drop the sword. Pseudocode
On Drop (){
mouse position = sword position on screen

}

How do I drop the sword in the same position as the mouse without the tip of the sword moving to the mouse?

Also keep in mind that UMG coordinates are not necessarily the same as screen coordinates.

Yes, effectively what I want it is the dropped position of the image to be the same as the mouse, rather than the tip of the sword moving to the mouse position.

So are you saying when you drop the sword into the world from the UMG, the worldspace sword appears in the world with its tip at the mouse screen position, but you want some other part of the sword to land there instead like the hilt?

It sounds like this is just an issue of the offset positioning of the image.
If that’s the case, then I’m not sure the exact solution off the top of my head, but I imagine the sword image is oriented with the tip of the sword in the top left corner of the image, which would be the 0,0 coordinate of the image bitmap itself.

So maybe it’s just that the sword is being positioned based on that top left coordinate.If you get the width and height of the image and divide those by 2 (or multiply by 0.5) then that should give you the offset you need to add to the coordinates to get the image centered on the mouse position.

You might also be able to configure the image widget to position itself by a center reference instead of the corner, and then you might not have to do that math to offset it at all.

Thanks for the reply mightyenigma. I will have a play around and keep you updated.

I have packaged the game to an ipad and the dragging is different to what it is on a PC. As I drag the sword on a tablet it doesn’t follow my finger. When I drag the sword, it moves at an offset from my finger rather than following my finger.