Customizing OVRGrabber to Increase Size of GameObject

Hello,

I’m wondering if it’s possible to override the behavior of the OVRGrabber script. Instead of grabbing an object and moving it, I’d like to modify its scale. Essentially, I would like to enable the behavior to grab an edge of a cube and make it bigger. I’ve already begun working on this in the script below, but it doesn’t look like a fluid motion.

 // Hands follow the touch anchors by calling MovePosition each frame to reach the anchor.
    // This is done instead of parenting to achieve workable physics. If you don't require physics on
    // your hands or held objects, you may wish to switch to parenting.
    protected override void OnUpdatedAnchors()
    {
        Vector3 handPos = OVRInput.GetLocalControllerPosition(m_controller);
        Quaternion handRot = OVRInput.GetLocalControllerRotation(m_controller);
        Vector3 destPos = m_parentTransform.TransformPoint(m_anchorOffsetPosition + handPos);
        Quaternion destRot = m_parentTransform.rotation * handRot * m_anchorOffsetRotation;
        GetComponent<Rigidbody>().MovePosition(destPos);
        GetComponent<Rigidbody>().MoveRotation(destRot);

        // DO THE MATH HERE
        // Calculate distance between where hand originally was and where it is now
        // That geometric distance should be the increased Y value in Scale of the object
        // (TODO): How to measure distance in 3D plane? Maybe only consider 2D change
        float distance = destPos.magnitude - handPos.magnitude;

        if (!m_parentHeldObject)
        {
            // Original Call
            // MoveGrabbedObject(destPos, destRot);
            AdjustObjectScale(distance);
        }
        m_lastPos = transform.position;
        m_lastRot = transform.rotation;

        float prevFlex = m_prevFlex;
        // Update values from inputs
        // CHANGING FROM PrimaryHandTrigger to PrimaryIndexTrigger to distinguish between grabbing and extending
        m_prevFlex = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, m_controller);

        CheckForGrabOrRelease(m_prevFlex);
    }


    protected void AdjustObjectScale(float distanceChange)
    {
        if (m_grabbedObj == null)
        {
            return;
        }

        GameObject gameObject = m_grabbedObj.gameObject;

        // Found @https://www.youtube.com/watch?v=e7I315b74HY

        // Could also probably use m_parentTransform.localScale because the parent of the script shoud be the GameObject
        Vector3 scale = gameObject.transform.localScale;
        // UNCOMMENT THIS LINE TO CHANGE BASED ON HAND MOTION
        // (TODO): Right now, doesn't work continously. One click and it jumps
        // Also, current calculation of distanceChange is off. Too big
        //scale.y += distanceChange;

        // UNCOMMENT THIS LINE FOR PRESS AND HOLD TO EXTRUDE
        scale.y += Time.deltaTime;
        gameObject.transform.localScale = scale;

    }

Try maybe scaling down the distance value before you use it. Divide it by 10 and see. If that’s too much, divide it by 2.

If you want smoothing, average it with its previous value (using some weight) and use the persistent slower-changing value.