Announcement

Collapse
No announcement yet.

[SOLVED] Mouse location to world space

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Can somebody please point me in the right direction, when using this with UMG Widgets. Im not able to get the mouse position when drag & dropping.

    For a better explanation. Im using kind of an Inventory with objects in it. When i drag the Inventory Item from the inventory into the world, i want to fire a LineTrace from that position & if it Hits an Actor start an Interace. All is working, when I Click on an Actor in World Space or drag an Object on it From the World. But when i Drag from the Widget, the is no mouse position to get.

    Any help is very appriciated! c.

    Comment


      #17
      Originally posted by charisti View Post
      Im using kind of an Inventory with objects in it. When i drag the Inventory Item from the inventory into the world, i want to fire a LineTrace from that position & if it Hits an Actor start an Interace. All is working, when I Click on an Actor in World Space or drag an Object on it From the World. But when i Drag from the Widget, the is no mouse position to get.
      On the Widget you're dragging, go to the Graph view and next to Functions, click from the Override option the dropdown item called On Mouse Button Down. Then also click On Drag Detected. In On Mouse Button Down, from Mouse Event, drag and create a node called Detect Drag If Pressed. Choose the Left Mouse Button (or whatever button you use to drag and drop!). Now connect the output to the return out.
      Now in On Drag Detected, you can drag from the Pointer Event and Get Screen Space Position on the mouse cursor. With a Deproject Screen to World node you could get World Space if you need it. The result can be Promoted to a Variable and then passed on later for whatever other needs you may have for it.

      Does this give you the desired functionality you wanted?

      Comment


        #18
        Works Great.

        Comment


          #19
          Originally posted by aGosh View Post
          but how to do if z not 0, and z=1000?
          Not correct if just "world direction" multiply by 1000.
          Not understand!!
          May be it's help some one.

          I use dotProduct insted. Direction and Z vector.
          70.f is the height from the ground (z = 70.f)

          Code:
          cosDir = FVector::DotProduct(Direction, FVector(0, 0, 1));
          SpawnLocation = Location + Direction * (Location.Z - 70.f) / cosDir * -1;
          Sorry that isn't blueprint.

          Comment


            #20
            Originally posted by Shrooblord View Post
            On the Widget you're dragging, go to the Graph view and next to Functions, click from the Override option the dropdown item called On Mouse Button Down. Then also click On Drag Detected. In On Mouse Button Down, from Mouse Event, drag and create a node called Detect Drag If Pressed. Choose the Left Mouse Button (or whatever button you use to drag and drop!). Now connect the output to the return out.
            Now in On Drag Detected, you can drag from the Pointer Event and Get Screen Space Position on the mouse cursor. With a Deproject Screen to World node you could get World Space if you need it. The result can be Promoted to a Variable and then passed on later for whatever other needs you may have for it.

            Does this give you the desired functionality you wanted?
            So obviously I'm almost 4 years late to this party but I'm doing almost exactly what you are saying but getting the PointerEvent from OnDragCanceled, then using GetLastScreenSpacePosition and feeding it into DeprojectScreentoWorld.

            This works perfectly in full screen but if in a windowed mode, like the editor, the trace seems to hit bottom-right to where it should do and not in a consistent offset it seems to be warped.

            If i multiply the result of GetLastScreenSpacePosition by GetViewPortSize / GetScreenResolution before plugging it into DeprojectScreentoWorld the offset is different, the trace hitting closer to the center of the viewport than where I stopped dragging, no matter what side of the screen it is dropped. Anyone have any idea what the problem maybe?

            Comment

            Working...
            X