Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Room Scale XR Rigs, is there a recommended method to implement walking movement on them?

Discussion in 'VR' started by JamesClow, Jan 29, 2020.

  1. JamesClow


    Jan 2, 2016
    I've been looking into some of the key differences between CharacterControllers and Rigidbody/collider based movement scripts, and it seems like the latter would have quite a few benefits over the former.

    So, I bought the Character Movement Fundamentals asset from the Unity store, which is a rigidbody-based character movement system, and tweaked the code to take inputs from the XR Input System. Motion is fine except for the rather monumental snag that the camera ends up well away from the XR Rig parent object where I placed it.

    This wouldn't be much of an issue if it weren't for the fact that the the rigidbody/collider/movement controller script are attached to the XR Rig parent object. To be honest, even if the camera transform did start off being the same as it's parent XR Rig, that would soon change with head movement, so I would need to move the XR Rig to stay in line with the Camera, but the Camera moves when the XR Rig is moved with it being a child object. Seems like you end up in an impossible situation. You end up with a rigidbody and collider that is in a different place to your camera, and no apparent means (to me) of keeping them together, which makes the combination unusable.

    I found Serious Sam TFE VR to be a wonderful experience for allowing me to use thumbstick walk/run and also physically moving so I could tentatively peek around corners, and just wanted to be able to implement the same wonderful VR movement capability myself for my own player..

    Unfortunately the XR interaction demo just seems to have snap turn and teleport in it's demo which begs the questions....

    Are XR Rigs the wrong tool for the capability I'm after?

    What is a/the/your preferred method to implement walking movement with XR Rigs?

    Any potential solutions or recommended readings would be very appreciated.
  2. JamesClow


    Jan 2, 2016
    I feel I should emphasize that I'm not after anyone writing a solution for me, just general pointers, I'm more that happy to bury myself in manuals, guides and tutorials, though I'm finding anything on this subject to be sparse.

    There doesn't appear to be any kind of feature roadmap, which leads me to wonder if this is something that is going to be geared mainly towards mobile based VR, and any PC based VR setups should be using OVR / SteamVR Rigs instead? My first impression is that the Unity XR packages are meant to be a replacement for the OVR /SteamVR rigs in the long term.

    I'm not sure if a lack of response so far is due to something fundamental I've missed or whether Unity XR is so early days that many others are in the same boat. It would be nice to hear anyone's thoughts.
  3. JamesClow


    Jan 2, 2016
  4. alexchesser


    Sep 15, 2017
    Hey - it sounds like you're looking for a way to move your player with the headset.

    I did a bit of research on this recently and think you might want to look at the asset VRIK package as part of FinalIK

    Sorry if I'm misunderstanding what you're hoping to do. I haven't played the serious sam experience so I don't exactly know :)
  5. JamesClow


    Jan 2, 2016
    Thanks Alex, that looks amazing, and I'll definitely have a look at that. I'm just after creating a rig with a rigidbody and Collider attached via smooth locomotion using touch controller joypad using the new input manager, and using a room-scale camera. Keeping a room-scale camera and a Collider attached to parent rig object together is proving tricky! Thanks to your reply to my previous post I'm at least happy that using the XR Rig is my best way forward and the VRIK in the video you've posted has got my interest. I tried to implement some IK on my rig and found the feeling of disconnect between the physical arms and VR arms didn't feel right, so I was just going to use some VR hands, but that would leave me with the issue of needing an avatar for multiplayer. This FinalIK might be the solution I need, though on brief glance I'm not sure it's going to help me with implementing walking/running with collider/rigidbody, as I need to be able to move with both camera and touch controller joypad and keep the collider in the right place. It definitely looks like a fantastic asset that I will end up using for IK. I just need to nail this movement solution first. :)

    Sorry if this response comes delayed. For some reason, this comment needs approval. Not sure what's triggered that, have I offended someone?
    Last edited: Feb 9, 2020
    alexchesser likes this.
  6. JamesClow


    Jan 2, 2016
    I decided to try and change the offset of the collider that is attached the XRRig parent object by subtracting the camera rig position from the rig position to get an offset for the collider that continually updates as the camera moves. This solves the issue of the collider being in the wrong place whenever I physically wander about or move my head. I'm sure there will be some caveats to using this as a solution which I will discover soon enough.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class FollowCameraTest : MonoBehaviour
    5. {
    6.     public Transform Rig;
    7.     public Transform Camera;
    8.     public Vector3 collidercenter;
    9.     private CapsuleCollider col;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         col = GetComponent<CapsuleCollider>();
    15.     }
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    20. = new Vector3(Camera.position.x-Rig.position.x, Camera.position.y-Rig.position.y, Camera.position.z-Rig.position.z);
    22.     }
    23.     void Awake()
    25.     {
    28.     }
    29. }
    Last edited: Feb 12, 2020
  7. hookmanuk


    May 28, 2013
    How did this work out for you?

    I've been looking for similar solutions, either using the Steam VR plugin or XR.

    The only solution I've seen that actually keeps the collider body in sync with the camera and also lets you move via the joystick is the VRTK 4.0 example.
    However I couldn't really work out what they had done, whenever I stripped back their sample it stopped working!
  8. rahebn


    Oct 30, 2012
    Hi friends.
    Try this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Unity.XR.CoreUtils;
    4. using UnityEngine;
    5. using UnityEngine.XR.Interaction.Toolkit;
    7. public partial class RigidbodyDriver : MonoBehaviour
    8. {
    9.     [SerializeField]
    10.     [Tooltip("The minimum height of the character's capsule that will be set by this behavior.")]
    11.     public float _minHeight;
    13.     [SerializeField]
    14.     [Tooltip("The maximum height of the character's capsule that will be set by this behavior.")]
    15.     float _maxHeight = float.PositiveInfinity;
    17.     private XROrigin _XROrigin;
    18.     private CapsuleCollider _capsuleCollider;
    19.     private Rigidbody _rigidbodyController;
    22.     protected void Awake()
    23.     {
    24.         _XROrigin = GetComponent<XROrigin>();
    25.         _capsuleCollider = GetComponent<CapsuleCollider>();
    26.         _rigidbodyController = GetComponent<Rigidbody>();
    27.     }
    29.     private void Start()
    30.     {
    31.     }
    33.     private void FixedUpdate()
    34.     {
    35.         UpdatePlayerCapsuleColliderRoomScale();    
    36.     }
    39.     public virtual void UpdatePlayerCapsuleColliderRoomScale()
    40.     {
    41.         if (_XROrigin == null || _rigidbodyController == null)
    42.             return;
    44.         var height = Mathf.Clamp(_XROrigin.CameraInOriginSpaceHeight, _minHeight, _maxHeight);
    46.         float skinWidth = 0.01f;
    47.         Vector3 center = _XROrigin.CameraInOriginSpacePos;
    48.         center.y = height / 2f + skinWidth;
    49.         _capsuleCollider.height = height;
    50. = center;
    51.     }
    53. }
  9. baggyg


    Nov 21, 2013
    If using HurricaneVR you can do this via the inbuilt PlayerController as it converts camera to playercontroller offsets into small movements. Otherwise if using Rigidbody then Hexabody is the way to go.

    But generally, take the delta of the camera from the body. Remove it but store the transform, then use a Vector.ProjectonPlane and move your base controller by that amount