Taking my first steps with this awesome tool, any help would be appreciated.

How do you implement drag and drop control with your mouse?

I put a rigidbody collider and an interaction machine on the game object I wish to drag.
Then, what do I put down in the schematic?
Am I missing any other necessary steps?

Thanks,
Gordon
  • Use the Mouse Drag start type on your Interaction Machine. For the drag, you can use different methods, e.g.:

    - Using mouse position change:
    You can get the mouse delta (i.e. position change since last frame) with the Mouse Touch Delta node, which stores the values into a Vector3 variable (X-axis being horizontal, Y-axis being vertical change).
    Now you'd use those values to change the position of the cube with one of the movement nodes.

    - Using raycasting:
    Use a Raycast node to find the position of the mouse in your scene, e.g. having the ground on its own layer helps to only check the ground and not other objecs. Now you can just place the object at that position (e.g. using a Change Position node), or manipulate the found position before placing the object (e.g. adding an offset or keeping the original Y-position of the object).
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
  • Thank you GIL.

    I'm still having difficulties getting the object movement synchronized with mouse movement. Could you be more specific how to configure the move node settings?

    I can almost get it to work, but then either the object moves faster than the mouse, or it becomes jumpy and jittery in the process. I'm sure all the settings make sense when trying to configure more advanced moves, but I'm really looking for the simple and classic drag and drop :-)

  • Getting good results with the mouse move delta and movement nodes is a bit tricky.

    It's far easier using the raycast approach - all you need is a Raycast node using the Screen raycast origin and Use Mouse Position enabled. Limit the layer mask to your ground layer (or some kind of invisible plane in your scene) and store the hit point into a local variable.
    On Success, use a Change Position node to set the object's position to the stored variable.
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
  • I'm getting the same results with the raycast node as I did with mouse delta.
    Mouse moves the object but only a tiny distance and not full mouse movement.
    I tried playing with "normalize" and "local position" but results were jittery and jumpy.

    Here's some screenshots, am I doing it wrong?

    image

    image

    image
  • Don't use normalize or local position for this. Try using a different Move Component, in my test I'm using the Transform and it works fine. Depending on the components attached to your game object, Auto will use different components for moving, e.g. rigidbody, which might not work as good for this kind of mechanic.

    Alternatively, you can enable Move and use a short move time (e.g. 0.1 or 0.01) to smooth the movement.
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
  • I created the project again from scratch and now it's working!

    However, I noticed that when I move my mouse fast enough, it "escapes" from the dragging interaction and stops moving. Is there a way to circumvent this so it will never stop dragging while mouse/touch is held?

    Thanks again for your help and patience, it has strengthened my confidence in this framework as a viable development tool.

    Gordon
  • edited May 2016
    I'm not sure if there's a way to prevent that escape from the dragging - it's the same as with handling it in a script directly, the mouse move is just faster than Unity's callbacks :)
    Post edited by gamingislove on
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
  • I'm sure you understand the Unity backend better than I do, but I think the issue comes from elsewhere. From my experience, drag functionality in other assets/scripts seems to avoid this escape syndrome. Could this be resolved via the more complex "Mouse Touch Position/Delta" solution? As it stands, games with quick mouse/touch moves will simply be broken by the raycast solution...
  • ORK's UI drags use the mouse position to directly update the position of dragged UI elements (i.e. no raycasting) and still has this issue.
    Maybe using the delta instead, or doing it in Late Update (tick machine) gets better results.
    If you're enjoying my products, free updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.