Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[HELP] HTC Vive - Grab object and move it along the Y axis

Discussion in 'Scripting' started by Shorkieboyo, Jun 18, 2017.

  1. Shorkieboyo

    Shorkieboyo

    Joined:
    Mar 10, 2017
    Posts:
    14
    Well, I don't think I have to say that I'm a beginner... I tried to make this work for the last day and
    I've given up.

    I want to grab an object with the GRIP button and move it along it's Y axis only.

    I watched countless tutorials but I just don't get it.

    Any ideas on how I'd be able to do this?

    Thanks
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Please show what you've done, as it's easier to comment/respond to code. Hopefully, that process will also shed some light on things for you, as to why & how things work/don't work.. :)

    I will preemptively suggest that you take a moment to glance at/read this page: https://forum.unity3d.com/threads/using-code-tags-properly.143875/
    It shows & explains how you can add code properly into the forums, so it's nice to read for everyone.
     
  3. Shorkieboyo

    Shorkieboyo

    Joined:
    Mar 10, 2017
    Posts:
    14
    Okay, this is what I'm currently working on:

    It's a drumming tool, and I want the handle (The one on the right, below the big cymbal (Ride)) to move the whole
    set (It being a child of the handle) on the Y axis.
    But I can't get it to work, I wrote some code that I put into each Vive controller but it's not working.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using VRTK;
    5.  
    6. public class handleHeight : MonoBehaviour {
    7.  
    8.  
    9.  
    10.  
    11. public bool hHeight;
    12. public GameObject handle;
    13.  
    14. private SteamVR_TrackedObject trackedObj;
    15.  
    16. private SteamVR_Controller.Device Controller
    17. {
    18.     get { return SteamVR_Controller.Input((int)trackedObj.index); }
    19. }
    20.  
    21. void Awake()
    22. {
    23.     trackedObj = GetComponent<SteamVR_TrackedObject>();
    24. }
    25.  
    26. void Start()
    27. {
    28. }
    29.  
    30. void Update()
    31. {
    32.         if ((Controller.GetHairTriggerDown()) && (hHeight == true))
    33.     {
    34.         Debug.Log("InPosition");
    35.         handle.transform.position = transform.position;
    36.      
    37.     }
    38.    
    39.  
    40. }
    41.  
    42. void OnTriggerStay(Collider col)
    43. {
    44.         {
    45.             hHeight = true;
    46.             Debug.Log("InHandle");
    47.          
    48.         }
    49. }
    50. void OnTriggerExit(Collider col)
    51. {
    52.         {
    53.             hHeight = false;
    54.             Debug.Log("OutHandle");
    55.          
    56.         }
    57.  
    58. }
    59.  
    60.  
    61.  
    62.  
    63.  
    64. }
    Please if you know how I can fix this, I'd be really grateful.
    Thanks
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I don't know anything about VR, however if all of the objects are part of the same parent, you could move the parent's y-position. If not, you can take a list/array of all the 'set pieces' you want to move and adjust their y position based on drag/move or whatever you'd like.
    Is acknowledging the grip/selection or whatever of your 'Handle" working at the moment?
    If it is, then whatever VR input for up/down direction change should be able to adjust, as mentioned above (those values)- doesn't that sound reasonable? :)
     
  5. Shorkieboyo

    Shorkieboyo

    Joined:
    Mar 10, 2017
    Posts:
    14
    It is not, the OnTriggerExit is not working, for some reason. The object detects collision but when it's outside the collider the OnTriggerExit is not working.
    How would the code for the "only move along Y axis" be?
    Thanks
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, just by setting the object(s) y portion to wherever you moved (maybe clamped in a range). Like adjusting based on the delta of the object you're moving (that acts like a lead to the rest of the drum kit)?

    You have to get the interaction (trigger or whatever works for you working) so you can move it :)