Search Unity

How would you do a position tracker?

Discussion in 'VR' started by SamPerCap, Sep 17, 2019.

  1. SamPerCap

    SamPerCap

    Joined:
    Aug 20, 2019
    Posts:
    3
    Hello there!:)

    I'd like to do like a spellcaster animation using oculus just for fun but I really want to hear from you how would you check if the player is doing a concrete movement.

    The point is that wearing the touch controllers, every time you do a specific movement like do a circle with the right hand in front of your stomach while the left is stand up to the left, a circle in front of you will move to the left until you do a different position.

    Right now, I am asking the player to do a T-Pose so I can save the distance of the controllers related to the headset and have in some way, the frame of the person. When the controllers are 0.1f away from the save position the T-Pose will be accepted.

    Code snippet from update() where:
    • PlayerPosition is OVRPlayerController (From Oculus Integration on the Asset Store)
    • LeftHand is CustomHandLeft (From Oculus Integration on the Asset Store)
    • leftT is Vector3

    Code (CSharp):
    1.  
    2. if (        (LeftHand.transform.position.x - PlayerPosition.transform.position.x) >= leftT.x - 0.1f &&
    3.             (LeftHand.transform.position.x - PlayerPosition.transform.position.x) <= leftT.x + 0.1f &&
    4.             (LeftHand.transform.position.y - PlayerPosition.transform.position.y) >= leftT.y - 0.1f &&
    5.             (LeftHand.transform.position.y - PlayerPosition.transform.position.y) <= leftT.y + 0.1f &&
    6.             leftT.x != 0.0f && leftT.y != 0.0f)
    7.             Debug.Log("Thats a T Pose on the x " + LeftHand.transform.position.x);
    8.  
    I think the code will be very slow and bad optimize if I had to do several if-statements on the update method just checking if the controller is right now on a concrete x or y. Do you have a better idea of doing this? :)

    Thanks in advice!
     
    ROBYER1 likes this.