Hello, we are trying to develop a VR game using the HTC Vive. We want the player to move in the direction in which they are looking when the touch-pad is pressed, but instead we move in the same direction no matter which way the player is looking. Here is a snippet of our Update function for movement:
Vector2 leftTouchPadValue = leftTouchPadAction.GetAxis(SteamVR_Input_Sources.LeftHand);
bool leftWasFalse = SteamVR_Input._default.inActions.TouchPadLeftPress.GetStateDown(SteamVR_Input_Sources.LeftHand);
bool leftWasTrue = SteamVR_Input._default.inActions.TouchPadLeftPress.GetLastState(SteamVR_Input_Sources.LeftHand);
bool rightWasFalse = SteamVR_Input._default.inActions.TouchPadRightPress.GetStateDown(SteamVR_Input_Sources.RightHand);
if (leftWasFalse)
{
transform.localPosition -= new Vector3(Time.deltaTime * leftTouchPadValue.x * speed, 0f, Time.deltaTime * leftTouchPadValue.y * speed);
} //end if wasFalse
else if (leftWasTrue)
{
transform.localPosition -= new Vector3(Time.deltaTime * leftTouchPadValue.x * speed, 0f, Time.deltaTime * leftTouchPadValue.y * speed);
} //end if wasTrue
Always worth to do a quick google first and read the official tutorials, as this question has been asked and answered countless times in a variety of ways:
TLDR: How does your code know what “forward” is ? Basically you need to include transform.forward in your calculations Unity - Scripting API: Transform.forward (the example on that even explains how to do this)
I have that same question, and I have spent a bit of time looking too. I want something that just takes a single step backwards).
The first article mentioned no longer exists.
The other ones use speed. One did not even consider that the direction that needs to be derived is not from the GameObject.
If you do not know the answer, then don’t say anything. Does anyone else have a relevant answer?