Search Unity

Question Need help with Touch Drag only Horizontal and Vertical with Clamp

Discussion in 'General Discussion' started by wuannetraam, May 23, 2023.

  1. wuannetraam

    wuannetraam

    Joined:
    Oct 29, 2019
    Posts:
    87
    So I have this project. It is for mobile devices. I have this eye and with your finger you have to move it sideways or up and down. Not diagonal. Also it should stay within the boundaries of the eye. Someone who can help me out with this? I prefer Visual Scripting but if you can explain it in C# I might understand it as well.
     

    Attached Files:

  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,137
    Get the vector of the start of the drag and limit it to the closest axis until the drag is released.
     
    neginfinity likes this.
  3. wuannetraam

    wuannetraam

    Joined:
    Oct 29, 2019
    Posts:
    87
    can you guide me in the direction how to do this?
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,137
    Get the position of the start of the swipe, get the position X amount of milliseconds after the start of the swipe. Subtract the second vector from the first and get the absolute value of the X and Y axis, see which one is bigger. If it's X, lock motion to that. If it's Y, lock motion to that.
     
    Last edited: May 23, 2023
    neginfinity likes this.