Search Unity

Foot Placement IK

Discussion in 'Animation Rigging' started by DebugLogError, May 5, 2020.

  1. DebugLogError

    DebugLogError

    Joined:
    Jul 24, 2013
    Posts:
    60
    I am trying to switch from Mecanim's built-in IK to the Animation Rigging package.

    My foot placement IK system is dependent on raycasting from the FK position of each foot before any IK is applied. Getting the FK position is straight forward with Mecanim's built-in IK, but it seems like I need to create an animation job to get the same result with Animation Rigging?

    If I go through the trouble of learning how to create that animation job I'm still not sure I will be able to raycast from within the animation job to get the information I need. The presentations on YouTube and the examples in GitHub all seem to avoid any physics based input.

    I would appreciate some guidance! This is a common use of IK and I'm sure others would benefit from an example implementation.
     
    Last edited: May 5, 2020
    cmann, easycardgame and Iron-Warrior like this.
  2. Jebtor

    Jebtor

    Unity Technologies

    Joined:
    Apr 18, 2018
    Posts:
    115
    Unfortunately, I don't think I have the answer you'd like to get but raycasting from animation jobs is not possible at the moment. The RigConstraints execute in animation jobs. Interaction with the physics world should happen from the main thread. With mecanim you do not run into this problem. To replicate similar behavior in Animation Rigging you would have to do the raycasting and feed the result as input into your constraints. Using Dots interaction between physics and animation should become much easier in the future.
     
  3. cmandrews

    cmandrews

    Joined:
    Jan 8, 2016
    Posts:
    9
    This is what is preventing me from using the animation rigging package as much as I want to. Because we cannot perform raycasts after animation, foot IK will always lag one frame behind without using some form of messy extrapolation.
     
  4. Jebtor

    Jebtor

    Unity Technologies

    Joined:
    Apr 18, 2018
    Posts:
    115
    I understand your frustration. I cannot wait until I can let my imagination go wild and integrate my animation tightly with physics. Due to the multi-threaded nature of both animation jobs and physics it is not trivial to have this work without large rewrites of many systems. However, this is something we keep in mind while working on the new animation and physics systems for Dots.
     
  5. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    You can do it modifying original script and binding vector3 position in job. Just try to understand their scripts.
     
  6. consolelw

    consolelw

    Joined:
    Mar 19, 2019
    Posts:
    5
    Hello. I've encountered the same problem as you mentioned. Do you have a solution on how to get the FK postion to do the raycast?
     
  7. consolelw

    consolelw

    Joined:
    Mar 19, 2019
    Posts:
    5
    I think DebugLogError's point is how to get the FK position of the bone where we do the raycasting. With Mecanim's built-in IK we can get the value by animator.GetBoneTransform() in OnAnimatorIK(), but when using Animation Rigging,not only in Update but also in LateUpdate, the bone position is the position after rigging.
     
  8. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Did anyone ever find a solution to this? Seems like foot placement based off raycast from FK would be a common use case (and unfortunately not having it being a major stopgap to using Animation Rigging at all).
     
  9. hawaiian_lasagne

    hawaiian_lasagne

    Joined:
    May 15, 2013
    Posts:
    124
    Jebtor has already stated it's not possible to raycast from the FK position using animation rigging due to the multithreaded nature of jobs.

    The best you can do is raycast inside update before the animator has run and feed this value into your jobs. It will lag, but it might not look that bad. If your game runs at 60fps I doubt anyone is going to notice a single frame lag on your feet ik ;)

    Or if you really want perfection do your foot IK placement inside LateUpdate instead, after animation rigging has run. You'll be back on the main thread though so may aswell stick to standard IK at that point.
     
    Jebtor likes this.
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I too would like to do this.

    Has anyone experimented with using the timing of the Playable graph and running the graph twice per frame? Like this:
    • Disable the IK nodes in the Playable graph and run. (only the animation runs)
    • Do the raycasting. The rig should be in the pure animated pose with no IK applied.
    • Disable the animation node in the tree and enable the IK nodes
    • Run the graph again. Now only the IK nodes should run.
    Is there a downside to this? It would be clearly less efficient but how slow would it be? Is there a reason this wouldn't work?
     
  11. Chainsawli

    Chainsawli

    Joined:
    Feb 7, 2017
    Posts:
    2
    I just got around and experimented with the animation rigging package. It's really powerful and nice ! I was also under the impression that I could go about and rig a character a bit like a full body IK, but it turns out to be impossible since the system is made to be a sort of override/make animation from scratch using unity animations. For a character that you already rigged in a 3D software it kind of defeat the purpose by re-rigging it again, then rig the controller for it. I mean I've done it yesterday and it's really cool to have a rig inside unity, but I would never do a prod animating characters inside unity it goes against my pipeline habit.

    What I ended up doing today tho realizing this limitations is : Make an Hybrid character from Final IK and Constraining the various target so that the motion would be really clean and automated when my programmer goes on to lerp the desired target positions. That way I was able to fix the twist bones (it's so nice to finally have something that works in that regards) in a rig layer, then added the arm controller motions and Center of mass motion to damp it a bit more. And most importantly Final IK handles the Foot replacement IK + is additive to the underlying animation.

    All in all it's a really neat way of doing secondary motion, or if you dare to animate a character inside unity there's at least a way to do it now ;), but otherwise I would much keep it as simple as it can get and keep this for fully procedural animations.
     

    Attached Files:

    hawaiian_lasagne likes this.