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: Using code tags properly - Unity Engine - Unity Discussions
It shows & explains how you can add code properly into the forums, so it’s nice to read for everyone.
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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class handleHeight : MonoBehaviour {
public bool hHeight;
public GameObject handle;
private SteamVR_TrackedObject trackedObj;
private SteamVR_Controller.Device Controller
{
get { return SteamVR_Controller.Input((int)trackedObj.index); }
}
void Awake()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
}
void Start()
{
}
void Update()
{
if ((Controller.GetHairTriggerDown()) && (hHeight == true))
{
Debug.Log("InPosition");
handle.transform.position = transform.position;
}
}
void OnTriggerStay(Collider col)
{
{
hHeight = true;
Debug.Log("InHandle");
}
}
void OnTriggerExit(Collider col)
{
{
hHeight = false;
Debug.Log("OutHandle");
}
}
}
Please if you know how I can fix this, I’d be really grateful.
Thanks
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?
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
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