Author Topic: Drag without mouse offset  (Read 2476 times)

Alraune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Drag without mouse offset
« on: July 02, 2015, 03:04:44 PM »
Hello, everyone. I've searched on forum but did not find an answer to my question, on drag & drop example when i pick an object he doesn't snap the center to my mouse cursor, it creates an offset that allow me to carry an item no matter where i click. But i want to snap the center of the item with my mouse cursor, how to achieve this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Drag without mouse offset
« Reply #1 on: July 02, 2015, 09:03:46 PM »
Actual movement happens in UIDragDropItem.OnDragDropMove by adjusting the localPosition (which is called from UIDragDropItem.OnDrag). If you want it to snap, you will want to look at UIDragDropItem.OnDragStart, overwrite it in your custom Drag & Drop class derived from this one, and set the transform's localPosition to what you need it to be.

Alraune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Drag without mouse offset
« Reply #2 on: July 03, 2015, 01:11:10 PM »
Actual movement happens in UIDragDropItem.OnDragDropMove by adjusting the localPosition (which is called from UIDragDropItem.OnDrag). If you want it to snap, you will want to look at UIDragDropItem.OnDragStart, overwrite it in your custom Drag & Drop class derived from this one, and set the transform's localPosition to what you need it to be.

Thank you! i was able to code my drag to do the behaviour i was searching.