0
\$\begingroup\$

I have a ready playerme avatar that I rigged with Final IK.

I downloaded an animation from mixamo to play with this avatar. My goal is to animate the avatar with the downloaded animation once a button is pressed on my oculus quest 2 controller. I am also using XR Interaction toolkit. However, I have not been able to completely do it. Below are the things I did

  1. Avatar is rigged with final IK
  2. Animation is downloaded from Mixamo with (FBX for unity) format
  3. downloaded animation is placed under Assets > Plugins > ReadyPlayer Me > Resources > Animations
  4. Animation is extracted from the fbx file
  5. I dragged the extracted animation (Clapping) into the Animator window. Made a transition from the 'Entry' state to it and then from it to the 'VRIK Animated Locomotion state' List item
  6. I created a boolean parameter, 'isClap'
  7. The transition from "Entry" to the animation, "Clapping" is given the condition. 'isclap' and set to true.
  8. The transition from "Clapping" to "VRIK Animated Locomotion" is also given same condition but set to false.
  9. I created a new action map with a new action and then binded it to the primary button on the oculus quest2 left controller
  10. I created the following script and added it to my avatar object. In the script, I intend to activate the animation by setting 'is clap' to true when the button is pressed and make it false when the button is released. This way, I can achieve my goal
using System.Collections;

    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;
    
    public class AnimatorScript : MonoBehaviour
    {
        Animator animator;
      
        public InputActionReference clap = null;
        
    
        // Start is called before the first frame update
        void Start()
        {
            animator = GetComponent<Animator>();
        }
    
        private void update()
        {
            clap.action.started += clapping;   
        }
    
        private void OnDestroy()
        {
            clap.action.started -= clapping;
        }
    
        private void clapping(InputAction.CallbackContext context)
        {
            animator.SetBool("isclap", true);
            //Debug.Log("now executing....: " + clap.action.GetHashCode());
        }
    
      
    }

Unfortunately, it's not working. I believe I'm missing a few things or something is not done right.

Update:

I started all over again. Without rigging, I wanted to see if my newly imported avatar can perform those animations by pressing the oculus controller button. It works, but the animation keeps going without stop.

This is simpler with OVR because it has mappings for button up, down and so on. I'm using XR for input mapping and I have no idea on how to change my boolean parameter, isclap to false when the button is released. I also used the Invoke() method to set a delay time to make it false after it has been true for a while. Still didn't work for me. updated code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class AnimatorScript : MonoBehaviour
{
    private Animator animator = null;
  
    public InputActionReference clap = null;
    

    private void Start()
    {
        animator = GetComponent<Animator>();
        clap.action.started += ClappingEnabled;
        Invoke("ClappingDisabled", 3f);
    }

    private void ClappingEnabled(InputAction.CallbackContext context)
    {   
      
        animator.SetBool("isclap", true);
        
        //Debug.Log("now executing....: " + clap.action.GetHashCode());
    }

    private void ClappingDisabled(InputAction.CallbackContext context)
    {
        animator.SetBool("isclap", false);
        //Debug.Log("now executing....: " + clap.action.GetHashCode());
    }

}

I have played around with isclap in play mode and the animation works pretty fine when alternating between true and false. Nothing much has changed from my previous trys, the only difference is that I have not done any rigging. I just attached the Mixamo animation and edited the avatar's default state machine below with my animation and added the isclap condition for transition.

enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I figured it out. Step 1 to 5 in my original question remains the same. Instead of creating a boolean parameter, I created a trigger (checkclap) instead.

I am making a transition from Any state to the clap state which has the clap animation. The transition from Any state has the condition checkclap and no condition for the transition from clap to VRIK_Locomotion. Step 9 remained the same and I added the below script to my avatar.

enter image description here

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class AnimatorScript : MonoBehaviour
{
    private Animator animator = null;
  
    public InputActionReference clap = null;

    //private Coroutine coroutine;


    //Start is called before the first frame update
    void Start()
    {
        animator = GetComponent<Animator>();
        
    }

    private void OnEnable()
    {
        clap.action.started += ClappingEnabled;
    }

    private void OnDisable()
    {
        clap.action.started -= ClappingEnabled;
    }

    private void ClappingEnabled(InputAction.CallbackContext context)
    {
        animator.SetTrigger("checkclap");
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .