Walking Development

As mentioned on the Walking Design page, I'm working on a way to walk for the players. The first step to figuring out how to walk is getting input from the trigger buttons. To do that I had to make a custom SteamVR binding.

To use the custom VR binding I made a function that keeps track of what buttons are being pressed. I want to keep track of both triggers seperatly, so I can later use that to determine which leg is moving. I also want to keep track of when the player releases the triggers, so I know that I need to switch to the other leg at that moment.

Move legs

Here's the function where I move the legs. First I take the direction that the player is looking at, so we can use that later to move relative to that direction. Then we check if the player can use its left leg and if it's holding the left trigger, if that's the case then we set some variables if this is the first time that it happens. After that we move the player towards its new position. If the player can't move left we check all the things for the right leg instead.

Rotate legs

If we don't rotate the legs relative to the player, we'll get some very strange results when you move your head around. With the following code we prevent this.

Transform legs

We use separate leg pivot objects to prevent the parent from transforming the leg values. Here we set the pivot object local position and transform equal to the left and right controller positions.

The whole script

Converting to OpenXR

We decided to switch the project from SteamVR to OpenXR, because of that I had to convert the leg movement code to still be able to use controller inputs.

It was fairly easy to adapt to OpenXR. First we make a script that extends the ActionBasedController script, to allow us to use custom input options without changing the ActionBasedController script.

After we've done that we make custom actions in XRI Default Input Actions, we bind them to the left and right trigger.

The next step is to add the CustomActionBasedController script to both controller objects. And afterward set the Use reference of the respective direction on true and add the Input we've made in the previous step.

Now that the setup is complete we're ready to add the inputs in the walking script.

In the start we want to reference each function that will happen on a button press or release.

The other parts of the scripts are generally the same, except that we set the walkHold boolean and the reset trigger booleans in the following functions:

Adding networking

Adding networking to the legs was quite easy with the OpenXR and Photon system that was mainly set up by my teammates. I just had to give the lefthand and righthand position to an already existing function, and that would allow the network to make copies that would only be visible by other players and position those copies correctly.

Sprint 4 iterations

During sprint 4 I made a bunch of iterations on the walking mechanic, you can read more about the design aspects in Walking Design.

Final iteration

I use the IsButtonPressed function to register a button press, in this new version of the script it doesn't matter if the left or right trigger is pressed, we decide the starting leg in a later portion of the script depending on the starting height of both controllers.

This coroutine rotates the legs to an idle standing motion:

MoveLegs is the main function that enables the user to walk. The user can walk by taking step after step. In this function I keep track of if there's a step and when it ends. Based on that we move the player.

The StartLegMovement function is mainly used for reseting values between a step. It also stops the rotateToNeutral coroutine.

Earlier we used the GetWalkSpeed function in the MoveLegs function, here's the code of the function. We calculate a speed based on the controller height but don't assign a negative speed when the controller moves backward. We do this by accidentally moving slightly backward at the end of a step.

Here's a playtester running in the game

Last updated

Was this helpful?