0

(I already followed the tutorial 002 from VRTK, to use the custom trigger event on right and left controller. And it do work, but not for what I want.) I do have a character instanciated from a prefab with his own Animatorcontroller. I attached to him my own "animator script", doing hand gesture when I press the button 0,1,2,3... and it's working and it work like that.

void Update()

   {
       // LEFT HAND //
       if (Input.GetKey(KeyCode.Keypad0))
           m_Animator.SetInteger("HandGestureLeft", 0); // FIST
       else if (Input.GetKey(KeyCode.Keypad1))
           m_Animator.SetInteger("HandGestureLeft", 1); // PALM
       else if (Input.GetKey(KeyCode.Keypad2))
           m_Animator.SetInteger("HandGestureLeft", 2); // POINT

Now I want to do it from my VR Controller buttons inputs instead of the 0.1.2.3 keypad. And I learnt that VRTK have some functions to do it. So I goes into the "VRTK_ControllerEvents_ListenerExample script" from the 002 example scene and I put the script on the left and right controller (Which are inside the VRTK gameobject scene) (not on my prefab avatar because if I do it nothing work anymore, the 002 scene script must be on the controllers instanciated by VRTK as the tutorial says). I can put animations inside and have them working. But they only work for my prefab if I put it inside the scene already, and do not instanciate it. So as a player I cannot have my gestures working, because when I hit play I must have my character instanciated for my game to work (And my default script does that well, when I press the 0,1,2,3... key because I do not need to have it on the hand controllers, I can have it on my prefab).

So I have a problem and they may be two solution from what I see. I may have a call to the VRTK controller functions directly inside my old "animator script". So it could look like :

if (Input.GetKey(KeyCode.Keypad0))

           m_Animator.SetInteger("HandGestureLeft", 0); // FIST

into if (GetComponent().TriggerPressed)==true) (BUT it tell me that TriggerPressed isn't available) m_Animator.SetInteger("HandGestureLeft", 0); // FIST

(But I have no idea how to grab the VR controller input from where VRTK is listening)

or there could be a way to have a call to my prefab AnimatorController Component inside the "VRTK_ControllerEvents_ListenerExample" script from the left and right controller. But here too, i have no idea how to call the prefab component, I can only call for the AnimatorControllerComponent if I have my Avatar Prefab on the scene already.

Well finally all I could need is the way to check from my prefab script if the leftcontroller or rightcontroller is pressing the trigger. Just like the "Input.GetKey(KeyCode.Keypad0)" but with the VRTK way to get the trigger input instead.

I'm totally lost, could someone help me ? :D

Here two images. Right now my working code look like that : ![1]: https://vrtoolkit.slack.com/files/UA39CMQRF/FA3BD4YD6/code.png "Code0" ![2]: https://vrtoolkit.slack.com/files/UA39CMQRF/FA3BD6DR6/code1.png "Code1"

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

1

Alright I found it finally. It was link that :

if(RightHand.GetComponent<VRTK_ControllerEvents>().IsButtonPressed(VRTK_ControllerEvents.ButtonAlias.GripPress) == true)
{
    m_Animator.SetInteger("HandGestureLeft", 0);
}