Search Unity

How can i scroll gameobject using touch?

Discussion in 'Scripting' started by Glowball123, Feb 5, 2021.

  1. Glowball123

    Glowball123

    Joined:
    Mar 10, 2016
    Posts:
    78
    i want to rotate my object as i drag my finger, and spin it when i swipe and release. I want to scroll the game object similar to how you would scroll ui
     
    Last edited: Feb 5, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    Plenty of tutorials out there on Youtube, or you're welcome to take a look at my project folder here.
     

    Attached Files:

  3. Glowball123

    Glowball123

    Joined:
    Mar 10, 2016
    Posts:
    78
    how can i make the scrolling inertia based, so that it keeps spinning for a while after i release the mouse or touch
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    I would track and record how fast it is rotating when the player has their finger down and is spinning it, perhaps averaged over a few frames.

    Then when their finger comes off, have code that continues to inject motion equivalent to the previously-taken reading, and slowly wind that down to zero over the next X amount of time.