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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Stop player from moving in the VR Play Area

Discussion in 'Scripting' started by tomjoe, Oct 12, 2017.

  1. tomjoe

    tomjoe

    Joined:
    May 11, 2015
    Posts:
    44
    Hello All,
    I am using SteamVR, and a Vive.
    My question is about VR play area movement.
    I want to stop the player's real-life-movement from affecting the player's in-game-movement. So the player can move around their own room in real life, and character in game will be frozen in place.
    I've tried attaching a rigid body and freezing all constraints, but no luck.
    it looks like the vive is overriding everything when the headset moves.

    basically what is happening is the player is in a river, and i want them to have to swim out, but right now the player can just walk out of because i have no way of locking down their play-area-movement.

    any help would be greatly appreciated.
     
  2. AdamAlexander

    AdamAlexander

    Joined:
    Jul 24, 2015
    Posts:
    73
    It sounds like what you're trying would be extremely disorienting! But if youre keen to try it you could parent a GameObject to the headset which compensates for the movement of the headset. Lets call this gameobject 'FreezeHeadset'. It might look like this in the hierarchy

    [FreezeHeadset]
    |___[Headset]

    Then attach a script to the FreezeHeadset with code like this:
    Code (CSharp):
    1. class FreezeHeadset extends MonoBehaviour
    2. {
    3.     public GameObject Headset;
    4.  
    5.     void Enable()
    6.     {
    7.         transform.position = Headset.transform.position;
    8.         Headset.transform.localPosition = Vector3.zero;
    9.     }
    10.  
    11.     void LateUpdate()
    12.     {
    13.         transform.position -= Headset.transform.localPosition;
    14.     }
    15. }
    I think this should do it. Whenever the headset moves the FreezeHeadset gameobject will move an equal amount in an opposite direction. Hope that helps and you may need a spew bag handy
     
  3. tomjoe

    tomjoe

    Joined:
    May 11, 2015
    Posts:
    44
    Thanks Adam,
    ill give it a try!
     
  4. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    I'll second the opinion that you really shouldn't do this. Not only is it disorienting, it can also actually be nausea inducing.
     
  5. Eltonr98

    Eltonr98

    Joined:
    Apr 4, 2018
    Posts:
    1
    void LateUpdate()
    {
    transform.position = Headset.transform.localPosition *-1;
    }

    This worked better for me, if someone else has trouble!