Jump to content

Dragging Sprite Whenever Screen is Dragged


coder_for_life22
 Share

Recommended Posts

I am currently trying to drag a sprite on the screen when the screen is dragged but I do not want the sprite to snap to the users thumb.

 

I've tried using OnDrag for the sprite itself but this requires the sprite to be touched and dragged.

 

I've also tried using the input managers x and y to move the sprite but this makes the sprite snap to wherever the use places their finger and then the drag happens. 

 

I would like the sprite to be dragged from its currently position but not snap to the users finger. So it the user touches the screen and drags the sprite drags too but only from where it is and not snapping to the location of the users finger.

 

Does anyone know how I can achieve this?

 

 

Link to comment
Share on other sites

Yup. I just implemented a solution a few minutes ago!

 

I first set a boolean when the screen is pressed and then set it to false when the pointerup is triggered.

 

In the update() I check the boolean and if its true that means we are dragging or the finger is down. I then just get the delta from the mouse movement. 

So the distance between the old mouse pos and the new mouse pos I then add this to the sprite to get it to work perfected.

 

In case anyone asks this in the future. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...