Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
vtheyoshi's avatar
vtheyoshi
Honored Guest
11 years ago

Movement control with leaning

Hi all,

I need help modifying the Player Controller script. I would like to create a game in which you move around the world by leaning forward and backward, much like the game Shadows of Isolation.

Leaning forward should result in forward motion and leaning backward should result in backward motion.

What part of the OVRPlayerController script controls translation based on the tracking data? Sorry for such a basic question.

I would like ultimately for the player to be able to hold down a button and gradually increase their speed, such that without holding down the button, they wouldn't move at all when leaning forward. But the longer they held down the button, the faster/further their lean would take them.

Any help you can offer would be greatly appreciated. I tried searching previous posts for answers and came up empty-handed, so I would also be glad to be directed to other related threads.

Thanks in advance!

8 Replies

  • I assume you are using Unity, which version? Are you using native VR Supported or the integration?
  • Thanks for your reply! I am indeed using Unity, 4.6 Professional at this time. I have imported the OVR package 6.0.0 and I am using the OVRPlayerController.
  • I think the easiest way to do this is to store the initial CameraRig position, and then change the movement speed to be the difference between that and the current position. You can get that value from:

    CameraRig.transform.localPosition
  • Thanks for your help! Right now I am getting my initial position in Update () right before the call to UpdateMovement() around line 179:

    initialPosition = CameraRig.transform.localPosition;


    Then, around line 300 at the end of UpdateMovement(), I am trying to alter MovementThrottle when the player holds down "L":

    if (Input.GetKey(KeyCode.L)) {
    MoveThrottle = CameraRig.transform.localPosition - initialPosition;
    }


    I thought it would be MovementThrottle that I should modify because based on the if (moveForward) lines above, it looks like that is what determines movement. I do have initialPosition declared as a private Vector3 at the beginning of the script.

    This does not allow me to move with leaning. What did I miss?
  • That's mostly correct, though you should set initialPosition in the Start() function so it's only set once.

    Alternatively, you can set initialPosition with a GetKeyDown(KeyCode.L).

    You'll also have to probably adjust the magnitude of MoveThrottle to get the correct speed.
  • Setting initialPosition in Start() now makes the L key into a forward movement key that does not take the position of the headset into account.

    As a result of the amount of lean not influencing movement with L, I can only move forward in the direction I start out facing.

    By adjust the magnitude, do you mean that I need to get the absolute value of the difference between the two positions? Using Abs() results in an error.

    Alternatively, perhaps I need to get a new initialPosition before I move each time, as you suggested, by using GetKeyDown. Does this need to happen inside the same call where I am subtracting the current position? A separate GetKeyDown(KeyCode.L) call in UpdateMovement() doesn't seem to do the trick, nor does putting the call in Update().

    Thanks again for you help. Sorry I need to be walked though this!
  • I was having some trouble getting this to work in Unity 4.6. I wonder, are you able to use Unity 5?

    Also, can you explain a little better exactly the behavior you are looking for? I may be able to find a solution.
  • I will update to Unity 5 now. (I've been waiting on my project manager to update our pro licence, but I don't need pro to solve this problem!)

    Sorry my explanation wasn't clear. I would like to be able to move forward at a slow pace whenever I lean a tiny bit forward with more forward leaning resulting in a slightly faster speed, and to then be able to move backward at that same slow pace whenever I lean backward. Additionally, I would like to be able to move diagonally by leaning diagonally, or alternatively, turn in a swivel chair to change my heading and then move again by leaning forward.

    Finally, I would like to be able to adjust my speed by pressing a button, such that holding it down I could gradually build up speed and move faster and faster, as long as I was leaning forward (though it's fine or possibly even better if I don't come to an immediate stop as soon as I sit up, especially if I've been going fast).

    I hope that makes more sense!

    EDIT: I was making it trigger only when holding down L because I was concerned that an accidental head movement might cause unwanted translation. I thought that holding down a key would be a nice way to keep the player still until you wanted to start moving, but I am not attached to this if it makes it more difficult to get lean-based movement.