Search Unity

Unity for OculusGo: Move an object along the z axis by touchpad

Discussion in 'VR' started by Arsandis, Nov 8, 2018.

  1. Arsandis

    Arsandis

    Joined:
    Sep 25, 2018
    Posts:
    20
    I have written a script to pick an object with a rigidbody component by the ray casted from the controller and move it around. I make the object, the child of the controller to move it in the scene then. I already have a script to detect the object by the ray casted from a controller, picking it up and moving it up and down and left and right with the controller.

    Now , I want to make that selected object along the z-axis by using the touchpad of oculus go. However I am not sure how to do it. This is the function i am using it to attach to the parent:

    Code (CSharp):
    1.  public virtual void Store(Transform NewParent)
    2.     {
    3.         //The following stops the object being effected by physics while it's in the players hand
    4.         rb.isKinematic = true;
    5.         //And fixes it to the new parent it is given by the player script to follow.
    6.         transform.parent = NewParent;
    7.         //It then resets it's position and rotation to match it's new parent object
    8.         //transform.localRotation = Quaternion.identity;
    9.         //transform.localPosition = Vector3.zero;
    10.     }
    and then i use it in the pointer class to attach it to the ray:


    Code (CSharp):
    1. void Intract()
    2.     {
    3.         //We set up the input "OculusPrimaryIndexTrigger" in the Input manager
    4.         if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
    5.         {
    6.             selectVisual.ClearObject();
    7.             //Check if you are holding something you can throw first
    8.             if (inHand != null)
    9.             {
    10.                 inHand.Release(controllerRef.forward, throwForce);
    11.                 inHand = null;
    12.                 //We do this check here to prevent Errors if you have nothing selected
    13.             }
    14.             else if (selectedObject != null)
    15.             {
    16.                 //Check if you can pick up the selected object second
    17.                 if (selectedObject.GetComponent<PickUp>())
    18.                 {
    19.                     //Beacuse PickUp is a child of PropBase, we can ask InHand to store selectedObject as PickUp, rather than use GetComponent
    20.                     inHand = selectedObject as PickUp;
    21.                     inHand.Store(holdingRef);
    22.                     //If non of the above were valid then simple call the trigger function of the selected object
    23.                 }
    24.                 else
    25.                 {
    26.                     selectedObject.Trigger();
    27.                 }
    28.             }
    29.             //If you have a object that you need to hold down a button to intract with
    30.         }
    31.      
    32.         else if (pointerOver != null)
    33.         {
    34.             if (pointerOver.GetComponent<PropBase>())
    35.             {
    36.                 selectedObject = pointerOver.GetComponent<PropBase>();
    37.             }
    38.             else
    39.             {
    40.                 selectedObject = null;
    41.             }
    42.         }
    43.         else
    44.         {
    45.             selectedObject = null;
    46.         }
    47.  
    48.     }
    49.  
    50. }
    If anyone could point me in a right direction or help me with this, I would greatly appreciate it!

    Thanks in advance