- Home /
The question is answered, right answer was accepted
Player walks in the direction the vr camera is looking?
I want that my player walks in the direction i look in Vr but when i turn my head i want my my character to move to there . so i mean where im looking is forward but i dont get. i tryed it almost a week now and i cant figure it our pls help. i have empty object tagged Player and a child of it is the Camera tagged MainCamera. the player has an Character Controller.
void Update()
{
if (GvrControllerInput.IsTouching)
{
ddTouchpadPos = GvrControllerInput.TouchPos;
if (ddTouchpadPos.y < 0.5f - deadZone)
{
normalizedDDTouch = new Vector3(0, 0, -0.08f);
}
if (ddTouchpadPos.y > 0.5f + deadZone)
{
normalizedDDTouch = new Vector3(0, 0, 0.07f);
}
if (ddTouchpadPos.x < 0.5f - deadZone)
{
normalizedDDTouch = new Vector3(0.07f, 0, 0);
}
if (ddTouchpadPos.x > 0.5f + deadZone)
{
normalizedDDTouch = new Vector3(-0.08f, 0, 0);
}
transform.localPosition += normalizedDDTouch;
}
}
Answer by Hellium · Sep 28, 2017 at 10:56 AM
First of all, add a reference to the camera's transform :
public Transform cameraTransform ; // Drag & drop here the transform of the camera rotated by the VR plugin
Then, use the local axies of the camera to move your object
if (ddTouchpadPos.y < 0.5f - deadZone)
{
normalizedDDTouch = Vector3.ProjectOnPlane( cameraTransform.forward, Vector3.up ) * -0.08f
}
if (ddTouchpadPos.y > 0.5f + deadZone)
{
normalizedDDTouch = Vector3.ProjectOnPlane( cameraTransform.forward, Vector3.up ) * 0.07f
}
if (ddTouchpadPos.x < 0.5f - deadZone)
{
normalizedDDTouch = cameraTransform.right * 0.07f
}
if (ddTouchpadPos.x > 0.5f + deadZone)
{
normalizedDDTouch = cameraTransform.right * -0.08f
}
transform.localPosition += normalizedDDTouch;
i just tested it after i build it and there it does not work so only in the editor do you know why?
Edit: i think camera doesnt rotate the empty object so anybody knows how to fix that ?
That works but now i have another question:
when i look down i get slower i wiggle. i think because he want to go in the direction im looking so in the ground can i limit that on just forward ?
Ty anyways was great help Pls keep going on :)
Answer by hlw · Sep 28, 2017 at 12:21 PM
If it only works in the editor, sometimes this kind of behaviour gets fixed by changing the script order in the project settings. Also, check if there is any float "is equal to/ x == y" (or something close to an is equal to) used to call the script that has to get called.
changing the script order does not help and i dont understand what you wrote at last
Follow this Question
Related Questions
Rotating GameObject Around Player With "Mouse Y" Position 2 Answers
Rotating objects to specific angle 3 Answers
Locking world rotation of child 1 Answer
Move towards VR Camera Orientation with Bluetooth Controller (Android) 0 Answers
Disable Windows Mixed Reality headset rotation/position tracking 1 Answer