Search Unity

Touch.position VS Touch.rawPosition

Discussion in 'Getting Started' started by Sparticus, Oct 23, 2020.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    Hey guys,

    What I want to do is detect how far they have dragged their finger across the screen. So I just need to calculate the distance between the position where they first touched the screen and the position where they lifted their finger.

    From what I have read in the docs it looks like Touch.rawPosition will tell me where they first touched the screen :

    However, when I print out the contents of rawPostion, namely the X value :
    Code (CSharp):
    1. Debug.Log(myTouch.rawPosition.x)
    It displays a value of 9.416726E-43 regardless of where I touch the screen.

    Obviously on Touch.BEGAN I could just save the Touch.position to a vector and use that, but if could use this rawPosition that would save me from creating a variable.

    Any idea what I am doing wrong?

    Thanks!
     
  2. paulyp1

    paulyp1

    Joined:
    Mar 25, 2020
    Posts:
    2
    I’m having this exact issue on Unity 2020.3.8f1 while simulating Apple iPhone 12 Pro using the device simulator preview package on Windows. Touch.position works fine, gives position in screen space convertible to world space. Touch.rawPosition however gives ~6E-43 and ~6E+10 for x and y values respectively.
     
  3. DrHerringbone

    DrHerringbone

    Joined:
    Jan 3, 2021
    Posts:
    13
    I'm having the same problem except when i convert to world space, it consistently comes up as (-4.8, -6.4) which is literally the bottom left hand corner of my screen.

    According to the documentation this means it is returning (0, 0) every time (my screen is 960px by 1280px with the origin being the center of the screen and 100px per world unit):

    Unity Scripting API: The bottom-left of the screen or window is at (0, 0). The top-right of the screen or window is at (Screen.width, Screen.height).
     
  4. Seruphenthalys

    Seruphenthalys

    Joined:
    Feb 10, 2021
    Posts:
    4
    Anyone got anything on this? I'm looking at touch.rawposition now, Unity 2021.2.10f1, using the simulator. Touches always have rawposition (0,0)
     
    Nit_Ram and spider853 like this.
  5. spider853

    spider853

    Joined:
    Feb 16, 2018
    Posts:
    42

    same, Unity 2021.3.16
     
  6. KevinCastejon

    KevinCastejon

    Joined:
    Aug 10, 2021
    Posts:
    109
    Same... Unity 2023.1.16
    Touch.rawPosition always returns 0,0 wherever I click the simulated screen.
     
    GildedGames likes this.