Skip to main content
Up and Coming
July 27, 2015

Detecting whether users are standing up or sitting down

Hello!

I'm not new to game development but I AM pretty new to developing with the Oculus Rift and C# in general. I'm trying to create a script that detects movement when players are using the Oculus Rift. Basically, I want Unity to detect if players are standing, sitting, or moving in between. Accordingly, I want the player size to shrink or grow based on their physical position. So if the player is standing, they're ginormous and if they're sitting, they'll be small.

So far, I haven't had much luck. I'm using Unity 5.1 (but can go to previous versions if needed) with the UnityEngine.VR integration. Form what I've seen, the integration doesn't seem to detect the Oculus Rift moving in the positive or negative Y direction. Frankly, I'm not sure where to go from here. This is for a class project and I can't seem to figure this out. Can anyone point me in the right direction or help me write some code to do this?

Thanks!
    This topic has been closed for replies.

    16 replies

    Up and Coming
    July 28, 2015
    I was thinking rather than Seated Or Standing that it was a analog range.. that you could scale up proportionally with the HMD height from seated.. take it further and SHRINK when the HMD goes below the seated position..

    Stand up your a giant..
    sit down your a person
    squat on the floor your a mouse
    Up and Coming
    July 28, 2015
    Yeah, my code above will do that: just change the min (yMaxSeated) and max (yMinStanding) range.
    Check out my Unity VR development blog: http://talesfromtherift.com @peterept
    Up and Coming
    August 10, 2015
    "wheatgrinder" wrote:
    I was thinking rather than Seated Or Standing that it was a analog range.. that you could scale up proportionally with the HMD height from seated.. take it further and SHRINK when the HMD goes below the seated position..

    Stand up your a giant..
    sit down your a person
    squat on the floor your a mouse


    Essentially that's what I'm trying to do.
    Up and Coming
    October 25, 2015
    Hello again!

    I'm commenting on this because I need some additional help with this prototype I'm developing. I'm currently using this code:

    using UnityEngine;
    using UnityEngine.VR;
    using System.Collections;

    public class SeatedOrStanding : MonoBehaviour
    {
    [Tooltip("Normalized Seated, Standing or Transitioning. 0..1 = Seated to Standing")]
    public float Standing;

    private float seatedY;

    void Start()
    {
    RecenterSeated();
    }

    void Update()
    {
    float y = UnityEngine.VR.InputTracking.GetLocalPosition(0).y;
    // y = transform.localPosition.y;
    float yMaxSeated = seatedY + 0.2f;
    float yMinStanding = seatedY + 0.4f;
    float rawStanding = (y - yMaxSeated) / (yMinStanding - yMaxSeated);
    Standing = Mathf.Clamp(rawStanding, 0f, 1f);
    }

    public void RecenterSeated()
    {
    StartCoroutine(RecenterSeatedCoroutine());

    }

    IEnumerator RecenterSeatedCoroutine()
    {
    InputTracking.Recenter();
    yield return new WaitForEndOfFrame();
    seatedY = InputTracking.GetLocalPosition(0).y;
    // seatedY = transform.localPosition.y;
    }

    }


    This is the one that peterept helped me write a while back. BUT I need to make an alteration to it: I need it to map with the player 1:1. In this prototype, I'm testing whether or not coupling physical movement with virtual camera movement is better when it's 1:1 or by an automatic trigger. Is there any way to alter this code so that it directly corresponds to the player as they gradually move up and down? Thanks!
    Up and Coming
    October 26, 2015
    Hey again,

    Could you clarify what you mean by 1:1 ? Do you mean that you just want the avatar to scale exactly with the user? In other words the eye level of the avatar always matches the eye level of the user (in physical space) ?
    Check out my Unity VR development blog: http://talesfromtherift.com @peterept
    Up and Coming
    October 26, 2015
    "peterept" wrote:
    Hey again,

    Could you clarify what you mean by 1:1 ? Do you mean that you just want the avatar to scale exactly with the user? In other words the eye level of the avatar always matches the eye level of the user (in physical space) ?


    Yes that is exactly what I'm looking to do. Basically if the player stops midway while standing up, the player avatar in game ALSO stops and scaling doesn't continue until the player physically moves again.