Vector3 changing z instead of x on first iteration

Hello all,
I am trying to create a script where i have a gameobject that moves via 2 finger touch on an AR app- across the x axis to change its x value and across the y to change its z. (up and down on the phone screen to go up and down / across to move the object across).
This works fine after the first iteration but is swapped on the first(up and down on the screen moves the object left and right).
It’s like a variable is not being initialised correctly on first iteration.
-this is inside my update method

 if (Input.touchCount == 2 && locked == false)
        {
            Touch touch = Input.GetTouch(0);
      
            obj.transform.position += new Vector3(0.001f * (transform.position.x + touch.deltaPosition.x ), 0.0f,
                0.001f *(transform.position.z + touch.deltaPosition.y));
        }

Thanks for the help in advance

Line 5 and 6… don’t write long hairy lines of code like that. Nobody on earth can reason about such a monstrosity and your bug is almost certainly located within there somewhere.

How to break down hairy lines of code:

http://plbm.com/?p=248

If your bug isn’t in there, at least by breaking it down you can prove that the bug is elsewhere.

My guess is it’s different with the first 2-touch registration by the device. Try it with only one touch and see if it’s consistent.

1 Like

That seems to make it a lot more consistent, thanks for the help.