Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

VR Touch Steering Wheel

nada.aly.332nada.aly.332 Posts: 1
NerveGear
So I wanna make a game with car controls just like this.
Currently using the latest version of Oculus Rift.
I'm so close to it but I can only code the joystick (of the left hand controller) to control the steering wheel, not the user's hands. 

The thought process behind the following code below is that: 
  1. Detect collision between user's hand and steering wheel (Success).
  2. Detect if user is gripping hand (Success).
  3. Detect if one hand is higher than the other (Can detect positions of both hands and compare values of the y-axis coordinates).
  4. Animate steering wheel based on which hand is higher. For example if the right hand is higher, rotate steering wheel to the right, left hand higher = rotate steering wheel to the left. (Fail) confused
[code=CSharp]using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Oculus_Steering : MonoBehaviour
{
    public GameObject rightHand;
    public GameObject leftHand;

    float maxTurnAngle = 45f;

    // Detect Collision with Player
    void OnTriggerEnter (Collider other) {

        Debug.Log("hello");
        Debug.Log("LEFT: "+OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger)+" and "+ Mathf.Abs(leftHand.transform.position.y));
        Debug.Log("RIGHT: " + OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger)+" and " + Mathf.Abs(rightHand.transform.position.y));

        //when leftHand elevation is higher turn wheel to left
        if (Mathf.Abs(leftHand.transform.position.y) > Mathf.Abs(rightHand.transform.position.y))
        {
            transform.localEulerAngles = Vector3.back * Mathf.Clamp(-97, -maxTurnAngle, maxTurnAngle);
        }
        else
        { //when rightHand elevation is higher turn wheel to right
            transform.localEulerAngles = Vector3.back * Mathf.Clamp(97, -maxTurnAngle, maxTurnAngle);
        }

    }

    void Update()
    {

        //for joystick; takes the horizontal input to determine if steering wheel should rotate left or right
        transform.localEulerAngles = Vector3.back * Mathf.Clamp((Input.GetAxis("Horizontal") * 100), -maxTurnAngle, maxTurnAngle);
    }

}
[/code]

I'm fairly new to unity and coding so if you need any more information, please don't hesitate to ask!
Thank you in advanced. 

P.S. I am currently using the latest version of Oculus Rift. I will provide the version of game engine, and a copy of the scene I am using in the comments below later in the morning. 

Edit: Using unity 2018.3.11f1 and the file is too large whoops.

Comments

  • konzeptzweikonzeptzwei Posts: 12
    NerveGear
    @nada.aly.332 hey there! did you have any luck? I have the same problem right now and could also use a little help!
  • nada.aly.332nada.aly.332 Posts: 1
    NerveGear
    @nada.aly.332 hey there! did you have any luck? I have the same problem right now and could also use a little help!
    @konzeo
    Yeah I did, it comes with bugs though. 
    It constantly detects the car as collision (not your hand) so you can steer the wheel even without touching it as long as one hand is squeezed. Really weird and frustrating to fix. Lmk if you find a solution. 

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Oculus_Steering : MonoBehaviour
    {
        public GameObject rightHand;
        public GameObject leftHand;
        public float maxTurnAngle = 45f;
    
        // Detect Collision with Player
        void OnTriggerStay (Collider other) {
    
            float leftPos = leftHand.transform.position.y;
            float rightPos = rightHand.transform.position.y;
            float leftSquez = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);
            float rightSquez = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger);
    
            if (other.attachedRigidbody) //issue == can steer wheel when not touching wheel if hands are squeezed 
            {
    
                Debug.Log("Debug: " + other.name + " "+other.tag );//debug print statement
    
                if ( (leftPos > rightPos) && (leftSquez > 0 || rightSquez > 0) ) //when leftHand elevation is higher, turn wheel to right
                {
                    transform.localEulerAngles = Vector3.back * Mathf.Clamp(97, -maxTurnAngle, maxTurnAngle);
                }
    
                else if( (leftPos < rightPos) && (leftSquez > 0 || rightSquez > 0) ) //when rightHand elevation is higher, turn wheel to left
                { 
                    transform.localEulerAngles = Vector3.back * Mathf.Clamp(-97, -maxTurnAngle, maxTurnAngle);
                }
                
                if (leftSquez == 0 && rightSquez == 0) //both hands not squeezing? set wheel to netural seat
                {
                    transform.localEulerAngles = Vector3.zero;
                }
            }
        }
    
        void Update()
        {
            //for joystick; takes the horizontal input to determine if steering wheel should rotate left or right
            if (Input.GetAxis("Horizontal") != 0){
    
                transform.localEulerAngles = Vector3.back * Mathf.Clamp((Input.GetAxis("Horizontal") * 100), -maxTurnAngle, maxTurnAngle);
            }
        }
    
    }

  • konzeptzweikonzeptzwei Posts: 12
    NerveGear
    hey @nada.aly.332
    thanks I will look into it! we will get through this ;)
Sign In or Register to comment.