Search Unity

[Solved] Setting Unity Steamvr 2.2 Locktopoint Only Oncollisionenter

Discussion in 'AR/VR (XR) Discussion' started by Giantbean, Apr 13, 2019.

  1. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    23
    I am learning Steam VR with the 2.2 release and the hands are a great. I can pick up objects and toss them around with the throwable script built into the SteamVR plugin. The issue is that all the objects have physics so its hard to place something back in a specific spot. Valve provided a LockToPoint script in the plug in which when used will snap an object back to a point when the object is released however I don't want to snap all the time. I only want to snap when I collide with a preset location and let go of the object.
    here is a snip from something I was trying

    Code (CSharp):
    1.      using Valve.VR;
    2.     using Valve.VR.InteractionSystem;
    3.     using Valve.VR.InteractionSystem.Sample;
    4.    
    5.      public GameObject AttachableObject;
    6.    
    7.     private void OnTriggerExit(Collider other)
    8.         {
    9.             if (other.gameObject.tag == TagName)
    10.             {
    11.                  AttachableObject.GetComponent<LockToPoint>().enabled = false;
    12.              }
    13.     }
    The simple idea is that this would turn off the snap to point when the object leaves its base station and another script with n OnTriggerEnter would turn the LockToPoint.cs back on.
    The idea works but with a major flaw that I have not been able to fix. The Flaw is that when you exit the home base with the LockToPoint and deactivate the scrip the ridged body of the object losses its Kinematics and pulls down on the hand holding it. If dropped it floats in place and when grabbed again it becomes kinematic as it should in the hand but each time you drop the object from then on it once again losses kinematics and floats in space.

    setting up a GetComponent(); and then telling it to turn off and on i.e

    Code (CSharp):
    1.      private Rigidbody body;
    2.      private void start()
    3.         {
    4.             body = GetComponent<Rigidbody>();
    5.         }
    6.    
    7.     private void OnTriggerExit(Collider other)
    8.         {
    9.             if (other.gameObject.tag == TagName)
    10.             {
    11.                 //...other lines redacted for clarity of the point being made
    12.                 body.isKinematic = false; // or true
    13.             }
    14.         }

    has not helped as the SteamVR scripts for the hand, throwable, and LockToPoint all seem to be competing with one another.

    Anyone know how I can make the script snap the object to a set transform and rotation only when it is colliding with the base station and the user/player has dropped the object?
     
  2. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    23
    FYI I can now pick up the object without it causing drag on the hand however when I let go it still floats in mid air.

    Code (CSharp):
    1.  public GameObject AttachableObject;
    2.  
    3. private void OnTriggerExit(Collider other)
    4.     {
    5.         if (other.gameObject.tag == TagName)
    6.         {
    7.           AttachableObject.GetComponent<Rigidbody>().isKinematic = true;
    8.          }
    9.      }
    Does anyone knows where the Steam VR hand gets set to use kinematics while being held and release kinematics when dropped.. I am thinking its in the throwable script but I am unsure how to access the function.
     
  3. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    23
    I was able to fix the issue with the following script on the object being attached and dethatched from the base station.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Valve.VR.InteractionSystem;
    5.  
    6. public class RemoveKenimaticOnRelease : MonoBehaviour
    7. {
    8.     private void OnDetachedFromHand(Hand hand)
    9.     {
    10.         GetComponent<Rigidbody>().isKinematic = false;
    11.     }
    12. }