Search Unity

Resolved XR Grab Interactable on character with Animator and avatar

Discussion in 'XR Interaction Toolkit and Input' started by basilwort5, Dec 29, 2020.

  1. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
    Can I use a XR Grab Interactable on a character with an Animator with a humanoid avatar? Ex King Kong picks up a character, with Animator to move character's arms and legs, and the Animator has a Humanoid avatar. But if King Kong grabs a foot, the foot and leg should move based on King Kong's grip.

    I've tried adding both to the character, but on start the leg points to (0,0,0), and does not respond to King Kong's grasp. If I change a setting in the Editor (like Update Mode), then the leg moves to a normal position and responds to King Kong's grasp.
     
  2. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
    I've tried a few things, and this is what I think happens:
    - XRGrabInteractable is on my character (eg, a Foot on character for King Kong to grab)
    - XRGrabInteractable removes the parent link to the shin
    - Animator with Avator begins animating the character
    - Animator reads Foot position properties which are (0, 0.4723, 0) from on the character
    - Since Foot does not have a parent, it moves Foot to (0, 0.4723, 0) in global coordinates

    When I change an Animator setting in the Editor, does it reload the Animator? That could be what allows it to figure out the Foot should be controlled by King Kong (he has a XRController and XRDirectInteractor for grabbing Foot)
     
    Last edited: Dec 31, 2020
  3. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
    One idea to resolve: add 2 characters to the scene, 1 with the Animator that will not be visible, and 2 with the XRGrabInteractable that will be visible. Add constraints to all the bones to the XRGrabInteractable character to do the same bone movement and rotations as the Animator character. This sounds like a horrible workaround, surely there must be a better way.
     
  4. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
  5. freso

    freso

    Joined:
    Mar 19, 2013
    Posts:
    73
    I assume the unparenting is for performance or race condition in movement. Obviously they should have made it configurable for people who know what they are doing, but...

    Unless I misunderstood the problem: When grabbing parts of objects/people, I think the best approach is to grab a separate object linked with physics to the "real" object. This way you will have physics enabled grabbing which looks and feels so much better. This is how all the good games do it (Saints & Sinners, Boneworks, HL: Alyx, etc).

    Add XRGrabInteractable (as an extra GameObject) to the foot. Link with a physics Joint to the actual foot bone. Now the FootGrabPoint can be unparented and moved, and the actual foot will follow the FootGrabPoint because it is linked with a joint. (Not sure, but you may need to set the movement type to Velocity tracked)

    Just by setting the weight of the rigidbodies, and some parameters in the joint, you can get heavy objects. (PS: I assume. I haven't actually implemented this yet myself ;))
     
    basilwort5 likes this.
  6. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
    Thank you for reply and suggestion. I didn't know they had the technique of a separate game object. The joint comment gave me an idea.
    What I have now : I added Position and Rotation constraints to the foot bone, with King Kong's hand as the source. This overrides the Animator with Avatar after a couple seconds into the game. I think this will work, I'll be able to have the Animator control most of the character, and the constraints will override it so hand controller can affect the part of interest.
    I just got this to work a few minutes ago, so much more to research. But I am surprised I have to add the constraints directly, why didn't XRGrabInteractable take care of it? Oh well, if that's what I have to do ...

    Next problem with this approach -- The Animator controller still causes the foot to move wildly on game start up. First, the foot stretches the leg and goes to near (0,0,0), then leg snaps it back to the length of the leg, then the foot goes to the hand controller. I need to figure out how to get it so the foot is at the hand controller. Maybe something to do with Start and Awake, or how Components are applied in order (no idea, just guessing, where I might start looking).
     
  7. basilwort5

    basilwort5

    Joined:
    Jan 1, 2020
    Posts:
    31
    I've changed the rig from Humanoid back to Generic. Humanoid has advantages of re-using animations from mixamo. But Generic works better with being grabbable. I was able to animate the Humanoid by using muscles in the Animation, but this was a lot more tedious than using Animation with the Recorder button for Generic. Plus I wanted to add facial animations, but the Humanoid and its avatar interfered with that too. Basically, go with the simpler, less advanced approach to get it done.

    At some time in the future, it looks like there are techniques of combining Humanoid rigs with Animation Rigging package for doing what I originally wanted to do, that I will have to spend the time to learn. I think this is the direction Unity intends as they have quite a few youtube videos out on it, and presented at SIGGRAPH.