Steam VR plugin help with Movement

  • I have movement mostly working just with a slight problem. I want the player to be able to turn the direction the head it facing while being able to move side to side and backwords. im using the navMeshAgent for player movement area. so i got the touch pad to move the player around however there I could not turn around. so then i started working with getting the player to turn and move the direction the player was looking but now i cant move sided to side or backwards. i can now only move the direction the player is moving..... think i need to combined the two some how.


    its only when I add the touchPadInput += Head.transform.forward; that he play actually move where they are looking but then no side to side or back words movement.

  • shouldn't it be changing Head.transform.position in line 37 and not touchPadInput?

    Head.transform.forward is just a unit vector in the direction you're facing.

    You can also make it so that you do the forward/backward movement separately from the turn.

    playerAgent.Move(touchPadInput.y *Head.transform.forward*movementSpeed);

    and then the rotation:

    Head.transform.rotation += touchPadInput.x;


    Alternatively, you can use slerp or something to make that turn smoother.

  • the head.transform.position is much worse then what 37 is. it makes the player go super fast and you cant turn your head to change directions (so it just goes in a straight line). Head.transform.rotaion += touchPadInput.x would need to be put as a new Quaternion to get the other vales. however that would not get me the forward direction. playerAgent.Move is a vector 3 so i have to form evertying around a vector3 some how. from what i can tell anyways.

  • Ok, one thing at a time...


    the problem with line 37 is that you're changing the touchPadInput by Head.transform.forward.

    touchPadInput += Head.transform.forward;

    is the same as

    touchPadInput = touchPadInput + Head.transform.forward;

    the result is that your touchPadInput changes. That should only be read from the touchpad itself.


    For the playerAgentMove input, the line I suggested was this:

    playerAgent.Move(touchPadInput.y *Head.transform.forward*movementSpeed);

    touchPadInput.y is a scalar.

    Head.transform.forward is a vector3.

    movementSpeed is a scalar.

    When you multiply them together, you have a vector3.


    as for the rotation with quaternions, just use quaternions.euler to transform the desired rotation angle to quaternions.

  • well I think there was something weird with the navmesh.move function. it would not let my player body move with the head direction. i switched it to transform.Translate and it worked. however even with me trying to smooth it out its jumpy. i thiink its because the head is attached to the player so when the body moves its also trying to move the players head at the same time. however i dont know if i can breake the steam.VR prefab and it still track the head but i can try. Unless im smoothing the body to the head wrong.

  • you can not take the head out of the prefab the body will walk away form the head but will move in the head direction. if you change the head to be setup in the inspector instead of though code that is. I tried making 2 quaternion. One with Quaternion bodyRotation = new Quaternion(0, playerTransform.rotation.y, 0, 0) and the other One with Quaternion headRotation = new Quaternion(0, Head.transform.rotation.y, 0, 0). Then i tried to use playerTransform.rotation = Quaternion.Slerp(bodyRotation, headRotation, turnBuffer) however that just ended up turn the player -180 and then the player could only move forward and back and sided to sided. I want the body to only turn on the Y axis to match the heads rotation.

  • ive used the code below and it almost works well. when i turn to the right it speed is grate however, when i turn to the left it speeds up super fast. so im amusing that the turn buffer (smoothness) is only being applied to the y's positive direction and when it goes to the y's negative direction it speeds up.


    Anyone know how i might fix this issue?

    see code below.

    Code
    1. void RotateBodyByLookDirection()
    2. {
    3. transform.RotateAround(Head.transform.position, Vector3.up, Head.transform.localEulerAngles.y * turnBuffer);
    4. }
  • ive used the code below and it almost works well. when i turn to the right it speed is grate however, when i turn to the left it speeds up super fast. so im amusing that the turn buffer (smoothness) is only being applied to the y's positive direction and when it goes to the y's negative direction it speeds up.


    Anyone know how i might fix this issue?

    see code below.

    Code
    1. void RotateBodyByLookDirection()
    2. {
    3. transform.RotateAround(Head.transform.position, Vector3.up, Head.transform.localEulerAngles.y * turnBuffer);
    4. }


    Try

    Code
    1. void RotateBodyByLookDirection()
    2. {
    3. transform.RotateAround(Head.transform.position, Vector3.up, Time.deltaTime * turnBuffer);
    4. }


    Then mess with the turnBuffer value and see what the results are.

  • I Tried that but it did not work. HOWEVER! i did fix the problem a different way and it fixed another issue i was having at the same time. I took the camera out of the Steam VR prefab (even thought a previous post i said this didn't work). I created a Empty game object and called it head. Placed the camera in the empty game object and made a new script that moved the head along with the body and placed new script on the head game object. then i went back to the function that rotated the body and used the code below.

    How this salved two problem i will explain.

    1. taking the head out of the prefab meant that when the play area / player rotated the head did not try to turn with it keeping it in the direction it was looking with out spinning out of control.

    2. the code below takes the body transform local Euler angles into a new vector 3 were we keep the x and the z the same but the y matches the heads. this allows the body to turn pretty smoothly were the head it looking but only on the y axis.


    Code
    1. void RotateBodyByLookDirection()
    2. {
    3. transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Head.transform.localEulerAngles.y, transform.localEulerAngles.z);
    4. }
  • UPDATE!!!!
    forget everything I've said before this is the fix for it!


    if you use the Steam VR Prefab do not remove any child objects just simply use the code or something like it.


    I was trying to turn the body which was the play area.... dont do that...


    I'm showing this code because there was no documentation on how to do this anywhere online. I was just messing with the overloads of the transform.Translate when I found this method.