1

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:

 public virtual void Store(Transform NewParent)
{
    //The following stops the object being effected by physics while it's in 
the players hand
    rb.isKinematic = true;
    //And fixes it to the new parent it is given by the player script to 
follow.
    transform.parent = NewParent;
    //It then resets it's position and rotation to match it's new parent 
object
    //transform.localRotation = Quaternion.identity;
    //transform.localPosition = Vector3.zero;
}

and then i use it in the pointer class to attach it to the ray:

void Intract()
{
    //We set up the input "OculusPrimaryIndexTrigger" in the Input manager
    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger))
    {
        selectVisual.ClearObject();
        //Check if you are holding something you can throw first
        if (inHand != null)
        {
            inHand.Release(controllerRef.forward, throwForce);
            inHand = null;
            //We do this check here to prevent Errors if you have nothing 
selected
        }
        else if (selectedObject != null)
        {
            //Check if you can pick up the selected object second
            if (selectedObject.GetComponent<PickUp>())
            {
                //Beacuse PickUp is a child of PropBase, we can ask InHand 
to store selectedObject as PickUp, rather than use GetComponent
                inHand = selectedObject as PickUp;
                inHand.Store(holdingRef);
                //If non of the above were valid then simple call the 
trigger function of the selected object
            }
            else
            {
                selectedObject.Trigger();
            }
        }
        //If you have a object that you need to hold down a button to 
intract with
    }

    else if (pointerOver != null)
    {
        if (pointerOver.GetComponent<PropBase>())
        {
            selectedObject = pointerOver.GetComponent<PropBase>();
        }
        else
        {
            selectedObject = null;
        }
    }
    else
    {
        selectedObject = null;
    }

    }

}

If anyone could point me in a right direction or help me with this, I would greatly appreciate it!

Thanks in advance

Ali
  • 53
  • 7
  • Use `OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);` to retrieve the position of your finger on the touchpad (a Vector2 from -1.0f to 1.0f), then move your object accordingly. – Remi Nov 09 '18 at 00:38
  • I used something like this inside the interact function but didn't work: `holdingRef.transform.Translate(new Vector3(0, 0, OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad).y));` – Ali Nov 09 '18 at 09:04
  • Does it work with `OVRInput.Axis2D.PrimaryThumbstick`? You should log the values to see if you get the correct values... – Remi Nov 09 '18 at 09:42
  • I am using it on oculus go, which doesn't have primarythumbstick. also since i am using touchpad to move and can only test it after building this to the device, will the debug work? – Ali Nov 09 '18 at 10:04

0 Answers0