what is the best way to trigger my own script attached to an object when it is grabbed. The object has the VRTK_Interactable Object script attached and all that functionality works.
Thanks
A bit more research on my own would have figured it out.
code here for others reference..
using UnityEngine;
using VRTK;
using System.Collections;
public class Team3_Interactable_Object_Extension : MonoBehaviour {
// this script demonstrates how to detect when this object has been grabbed by a controller.
// it requires the object already have the VRTK_InteractableObject attached.
// it simpley subscribes to the event generated by the interactable object script.
// there are many more events to subscribe to so lots of interaction options are posible.
// use this script to ADD functionality to your object not provied by the VRTK scripts.
// this could include triggering other actions based, etc.
// a full list of events can be found in the interactable object script.
// Use this for initialization
void Start ()
{
//make sure the object has the VRTK script attached...
if (GetComponent<VRTK_InteractableObject>() == null)
{
Debug.LogError("Team3_Interactable_Object_Extension is required to be attached to an Object that has the VRTK_InteractableObject script attached to it");
return;
}
//subscribe to the event. NOTE: the "ObectGrabbed" this is the procedure to invoke if this objectis grabbed..
GetComponent<VRTK_InteractableObject>().InteractableObjectGrabbed += new InteractableObjectEventHandler(ObjectGrabbed);
}
//this object has been grabbed.. so do what ever is in the code..
private void ObjectGrabbed(object sender, InteractableObjectEventArgs e)
{
Debug.Log("Im Grabbed");
}
}
Newbie here, how would I use the sender object to give me the rotation of the controller?
I'm trying to do this once on pick up:
grabbedObject.transform.rotation = Quaternion.Euler(controllerX, controllerY, controllerZ);
To simulate picking up a new controller.
Wait, I figured it out:
controllerX = e.interactingObject.transform.rotation.x;
controllerY = e.interactingObject.transform.rotation.y;
controllerZ = e.interactingObject.transform.rotation.z;
gameObject.transform.rotation = Quaternion.Euler(controllerX, controllerY, controllerZ);
But this seems to be knocking the object out of my hand when it rotates?
But if someone has a similar problem in the future, a slack conversation is impossible to google?
Then you should use stack overflow with the vrtk. All slack messages are archived but if you want a forum based conversation then use stack overflow.
The issue template describes this.
Awesome, this helped me so much understanding how to connect events to handlers
Most helpful comment
A bit more research on my own would have figured it out.
code here for others reference..