Search Unity

Mecanim Foot Placement

Discussion in 'Assets and Asset Store' started by BrUnO-XaVIeR, May 31, 2013.

  1. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hi JPM, these weight float values you can get from curves you create in your FBX files.

    Check these docs: http://docs.unity3d.com/Documentation/Manual/AnimatorCurves.html
    When you create a curve on a model asset's animation import settings, you can create curves and give them a name.
    Create on your mecanim controller a parameter with the same name of the curve you've created and when mecanim is playing a state with that animation clip it will update the parameter you named with the name of the curve you've just created :)
     
  2. JPM1987

    JPM1987

    Joined:
    Jul 11, 2013
    Posts:
    3
    Ah thank you. I understand the meaning of LFP and RFP (what I need to set in the animation curves). But can you tell me what I need to do with LFP-R and RFP-R? I think this would be all I need for today :)
     
  3. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    You don't need those extra curves unless you want to control rotation from a separate paramenter. You can just use 1 curve for both left position/rotation and another one for right pos/rot.

    I gave an example of using 4 curves just to let you know that you can customize rotation and position weights separately.
     
    Last edited: Jul 24, 2013
  4. brave_mike

    brave_mike

    Joined:
    May 8, 2013
    Posts:
    26
    Hello BrUnO XaVIeR. Is there some succes with the foot prediction?
    Your system works great!
     
  5. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hello Brave Mike.
    No not yet, I think many things will have to be reworked. I have few ideas but couldn't try them for now.
     
  6. jessee03

    jessee03

    Joined:
    Apr 27, 2011
    Posts:
    729
    I was just thinking about this and then decide to check the forums and here it is. Great job : P
     
  7. Crazy Robot

    Crazy Robot

    Joined:
    Apr 18, 2009
    Posts:
    921
    Hello,

    I just bought this asset and I need a bit of help setting it up.

    I have a NPC navagent that is on a terrain. The NPC also has capsule colliders on it's legs and arms.

    The NPC's layer is Enemy and the terrain, along with all other static walkable game objects, layer is Default.

    When I use the auto call with "do" set to true, the legs shoot up into the NPC's chest and wiggle around. Clearly the raycast is having issues.
    If I turn the colliders off, then the legs shoot straight down, past the terrain and the feet are also down. the offset can adjust this a little, but they're still messed up.

    So, how can I get this to work with my setup of colliders on the legs and the terrain?

    Thanks,
     
  8. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hello Crazy Robot. I believe raycast is hitting your colliders on character's joints.
    There are functions there where you can tell the raycast to hit things from terrain layer only.
    Are you using function variation where raycast ignores anything from 'Character' layer while its colliders are from that layer for example?
    If so, I'd like to help but I need an isolated repro small project so I can point to you exactly what to do to work around your issue.
    It's for sure just a problem with layers.

    For example, the function using auto curves, but raycasting only a given layer would be this one:
    Code (csharp):
    1.  
    2. public static void FootPlacement(this Animator animator, bool Do, float HeelOffset, float FeetOffset, LayerMask Mask) {
    3.   //...
    4. }
    5.  
    Where the LayerMask may be a public LayerMask declared on your controller to use on the function. And from there you select only the terrain layer on your controller inspector.
     
    Last edited: Nov 3, 2013
  9. TenTickles

    TenTickles

    Joined:
    Nov 17, 2012
    Posts:
    10
    Hi,

    I was just wondering if this is designed to work with the default unity character controller, or if I will be able to easily integrate Mecanim FP with my own custom character controller?
    If it is built around the default unity character controller, any pointers on what I need to build into my custom controller would be great.
    Thanks!
     
  10. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hi. It is designed to be used with any bipedal characters with Pro's IK system.
    Character controllers doesn't really affect the results as soon as you activate IK passes on layers. If you have any problem let me know.
     
  11. vonflow

    vonflow

    Joined:
    Mar 21, 2013
    Posts:
    3
    Hey there,

    So, this is kind of a weird thing that I've been banging my head about for a while. Maybe an easy fix... maybe a bug... I don't know. Whenever I set FootPlacement to use a LayerMask, I get the error "Scene::raycastClosestShape: The maximum distance must be greater than zero!"

    I'm not really sure what it's on about since it works fine without the LayerMask. I've tried the auto curve mode and manual, both throw the same error when a LayerMask is introduced.

    Also it would be really amazing if it would support stairs a little better (maybe it already does with some more fiddling), but if the back of the foot is on one step and the front on another, the foot kind of goes at a 45 degree angle through the step. Not sure how easy it would be to just move the foot to one step or another, but it would be neat.

    Thanks for a the fun asset
     
  12. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hi, that error may be something introduced on new version of Unity. Are you using 4.3?
    I will take a look and try to reproduce that error and find out what is going on.

    The issue with stairs, you could use a variation where the IK adjusts only heels while on stairs, ignoring the feet.
    If hit.object.name.
     
  13. vonflow

    vonflow

    Joined:
    Mar 21, 2013
    Posts:
    3
    Ahh yes, the heel only detection makes sense. I'm on 4.3.1f1 at the moment.
     
  14. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Well, I've been trying to reproduce this, but no luck. I know Unity 4.3 has a lot of new bugs and this may be related, but everytime I use the methods on my Unity installations... It just works, no warnings, no errors :|
    Maybe your raycast is hitting character's layer? Your layers should be setup in a way where the raycast can ignore colliders attached to the character itself.
     
    Last edited: Dec 18, 2013
  15. Co0l

    Co0l

    Joined:
    Dec 21, 2013
    Posts:
    3
    Same issue here. Even with layer function raycast is hitting my character leg collider. When I assign IgnoreRaycast layer to the character, everything work fine
     
    Last edited: Dec 21, 2013
  16. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    If you can package a .unitypackage scene I can take a look on what is happenning, but I'm pretty sure on your Physics settings, there's something wrong with the layers collison matrix.
    I'll see if I can find a way to make raycasts auto ignore character colliders because this has become a common issue for new users.
     
  17. Co0l

    Co0l

    Joined:
    Dec 21, 2013
    Posts:
    3
    The problem was in calling Physics.Raycast() method. Mask value should be 4th param

    Code (csharp):
    1.  Raycast(ray: Ray, hitInfo: RaycastHit, distance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers)
    Fix looks like

    Before
    Code (csharp):
    1. Physics.Raycast(L_Y, out LYH, Mask.value)
    After
    Code (csharp):
    1. Physics.Raycast(L_Y, out LYH, Mathf.Infinity, Mask.value) {
     
    Last edited: Dec 22, 2013
  18. JohnPet

    JohnPet

    Joined:
    Aug 19, 2012
    Posts:
    85
    Will this thing work with a character controller or capsule collider?
     
  19. Co0l

    Co0l

    Joined:
    Dec 21, 2013
    Posts:
    3
    Yes, it will
     
  20. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Oh, a missing parameter :O
    I really didn't see that, will fix it asap! Thanks!
     
    Last edited: Jan 25, 2014
  21. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Fix for layerMasked methods submitted.
    Luckly it will be live this week.
     
    Last edited: Dec 23, 2013
  22. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hey guys, I’ve added support to Final IK; Only for its BipedIK class for now. Was pretty simple, syntax is still the same.



    Sample controller script:


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using RootMotion.FinalIK;
    4.  
    5. // Example of how to use the MFP class with FinalIK.
    6. // Add this to your Mecanim Character with 'FinalIK' and follow the Guide to understand how to use it.
    7.  
    8. [RequireComponent(typeof(BipedIK))]
    9. public class MFPFinalIkExample : MonoBehaviour {
    10.     public bool Do;                         // If need to turn off placement for any reason.
    11.     public float HeelOffset;                    // Fine adjustment of heels.
    12.     public float FeetOffset;                    // Fine adjustment of feet.
    13.     public LayerMask Mask;              // Raycast Mask.
    14.     private BipedIK Actor;                  // The BipedIK component attached.
    15.     //
    16.     void Start() {
    17.         Actor = GetComponent<BipedIK>();
    18.     }
    19.     //
    20.     void LateUpdate() {
    21.         Actor.UpdateBipedIK(); Actor.FootPlacement(Do,HeelOffset,FeetOffset,Mask);
    22.     }
    23. }
    24.  
    However it deals with IKGoal rotations a bit different, but will be eay for you to fix artifacts using the ‘Maintain Rotation Weight’ parameter:




    Important:
    To use it with FinalIK’s BipedIK you of course must have the FinalIK package in your project and in the MFP.cs script uncomment the line:
    Code (csharp):
    1. //#define FINALIK
    Have fun! :)
     
  23. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    dude you are awsome, I was asking the final ik guy about the foot placement, then saw your thread... by the way how do you keep updating the walk or moving, seems like ik is stuck at intial position for final ik
     
    Last edited: Jan 25, 2014
  24. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hmm, I'm having no problem with animations here, could you show a screen or video of what is going on?
    I use curves to free weights on certain keyframes so it doesn’t keep feet pasted to the floor.

    Edit:
    I’ve found the issue of what you describe. Is just that FinalIK requires to call
    Code (csharp):
    1. animator.SetIKPosition(AvatarIKGoal.LeftFoot,L_Foot.position);
    BEFORE we process foot placement...
    Unity's system do not require that, its IK follows joints by default. I’ve fixed your issue and will PM you the fixed method and push an update to the asset. Thanks!
     
    Last edited: Jan 25, 2014
  25. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I have just bought thus to hopefully adapt it for our project. However, using the Mecanim example scene I cannot get curves to have an effect. No matter how they are set, foot placement seems to always be 100% active. Any ideas regarding what to check?

    Thanks in advance!
     
  26. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hi! If you are using curves, Unity requires you to setup a variable on your Mecanim graph with same name of your curve.
    Are you doing that? Like this: (click for larger image)

     
    Last edited: Jan 29, 2014
  27. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    No, I was under the impression the only thing required was curve variables passed before the method call.
    I am calling the method
    where you list Eli Curtz as creator and state that it will support custom curves without FBX.

    I am not too experienced with Mecanim yet, so apologies if I missed something obvious I should have known. :)

    Another odd thing I have noticed is that the transform for the hips returned by the animator has a height of zero. So in the example Mecanim package the raycasts will fail when the avatar is running left or right as the raycasts will not hit the ground. Is that a Unity bug or expected behavior? I would have expected animator.GetBoneTransform(HumanBodyBones.Hips).position.y to return the actual global y position of the Hipsmaster. But unless I am very mistaken, it does not.

    Any thoughts on this?
     
  28. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hmm, this is strange. Bones transform should never return null.
    Could you post some screenshots of the issues you have?

    And yes, that method do not require curves, it creates its own curves and calculates which leg is leaving floor and removes IK weights from it.
    If it is not doing that, there is something to investigate yep.
     
  29. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    It is not returning null. Rather it is returning a position where x and z makes sense, but y is zero. It is as if the transform.position is in local space or at least relative to the pelvis - which is weird if it is supposed to be the true transform in world space.
    Regardless, the effect in the current script (in 4.3) is that the raycast goes from the foot and may therefor miss the ground. Please see the attached image where the white line is the ray that the script is casting and the red line is a ray from hips.position and direction 0,-1,0.

    The code generating this as copied from your script:
    It may have been a simple mistake on my end. I thought that method had an overload with toe transforms, but it did not so I called the simple version without curves. Anyway, supplying the right method with animationcurves via the script will work as intended I presume - no need to attach curves to animations for that one, right?

    Last but not least, thank you for the help!
     

    Attached Files:

  30. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    I’ve never seen this.
    Please, if you can pack this scene (and character assets too) and send to me I will investigate what is going on.
     
  31. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I will do some more troubleshooting first as this is most likely unrelated to your code. It is either a Unity bug or a project issue. I am installing 4.3.4 as I type this to check if it is a bug as 4.3.2 has a LOT of Mecanim fixes (I was on 4.3.1).
     
  32. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    By the way, have you started work on predictive foot placement etc. ?
    We need it for our project and have started research, but I thought I would ask first as it is rather pointless to reinvent the wheel. :)
     
  33. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Well, I built a prototype with predictive behavior, but it didn’t work as expected.
    I still have ideas about how to do it and will try it again pretty soon; As soon as I finish implementing localization on my in-Unity notepad I will start research on prediction again.
    We have to know where the foot is coming from, where it is going to before it ends up there, “learn” how to avoid trajectory obstacles and generate real-time animations to correct leg movement, etc. Tons of more processing then simple foot alignment, so it must be something that doesn’t eat too much resources while doing it well. Will try it soon :)
     
  34. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I just reproduced the problem in an empty project. Steps to reproduce:
    (Unity 4.3.4 and 4.3.1)
    - Create a new project containing only the Asset Store Mecanim example package and the current Basic Foot Placement
    - Open the Animation Controller Scene
    - Enable IK Pass on the animator
    - Add the following to the locomotion.cs:
    - And this to the MFP.cs (at line 784 or thereabouts):
    The result is exactly as in the previous pic. The Hips transform is indicated below the hip and at the character root. It is correctly placed in x,z but y is in the local 0 of the character space (ie. move the character on the y axis and the indicated hips position will move as well, but it is not starting at the hip as expected).

    Now again, perhaps this is intended behavior - it is not well documented in the Unity docs.

    If you would test it I would be very thankful. I could package it for you if you want to but the above steps takes a couple of minutes so I am not sure how much time it would save. :)

    Edit: Doing exactly the same with HumanBodyBones.LeftUpperLeg at the line below the above DrawRay does yield the expected result. This looks very much like a Unity bug - unless it is intended behavior for some reason. I am considering filing a bug report for it - what do you think?
     
    Last edited: Jan 29, 2014
  35. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I am considering cheating a bit to arrive at something good enough. If you looked at the GDC presentation about AC3 it does look good - but look closely and you can see their solution does intersect with obstacles and does not seem to do any major corrections regarding the foot placement. While absolutely not diminishing their work, I am not sure one would have to go too deep and still arrive at something that is a big visual improvement to "only" planting the feet at the end of the motion.
    We will see - I have the day tomorrow devoted to some testing now that I know how to work around the issues with the hips location and failing raycasts.
    Have to solve another issue first as well: We are integrating it with UMA so I will have to troubleshoot their bone rotations as well. At first glance it looks like their blender rig does not play nice with the adjustments in your script - but I may be wrong. :)
     
  36. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hmm... That wrong behavior may be that instead of using actual pelvis joints, that mecanim character has its root joint assigned as hips, And raycast is pointing to its root instead of pelvis thus raycast fails, I will download this new package and see by myself if that is the case.

    UMA, I had no time to really use it yet, I just took a look and didn’t try to use MFP.cs in any of its character, if it causes a problem author is doing something in LateUpdate() somewhere; For FinalIK you also must ensure you update its rig before footplacing, that proly is the case with UMA too.
     
  37. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Yep - that was it!
    I am still too ignorant about Mecanim to understand why they would rig it like that, but that solves the issue anyhow.

    About UMA, lateupdate might be an issue - I have to look for that - but in general I know that the rig they use has some offset rotations to account for it being rigged in Blender (which apparently uses another coordinate system). I briefly compared the bone rotations of a UMA character with the example one and they do differ. If you apply rotations in MFP (which I think you do - haven't looked closely) that will likely cause issues if the bone rotations on the target rig are not as presumed.
     
  38. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    I’m organizing myself to take a deep look in UMA this weekend, hope I can to do it if my girl don’t mind haha...

    Oh, a nice person from Square-Enix (couldn’t check) contacted me asking about terms of use. Looks like a team in Squeenix Japan is using Unity for an upcoming title and want Basic Foot Placement implemented, but I couldn’t ask any details about it. So cool, I’ve always loved Square’s games :)
     
  39. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Cool - congrats. Make sure you change your terms to include a royalty based fee. Just for them, of course. :) (Just kidding).

    Regarding UMA I am happy to report that this far I have not had any issues implementing foot placement with it. I am editing your code quite a bit and am adding predictive placement based on stride and obstacle evaluation etc. Working well this far, I am just hoping it won't take me as long as it apparently did for the AsC team. :)
     
  40. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Yep, I didn’t have any issue with UMA too. This is great, it is such a great character system! :)

    If you succeed on predictive placement, please show us a video. Would be great to see it, good luck!
     
  41. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    I’ve reworked the methods for FinalIK to make it more reliable;
    It is present on 1.34, if you are using this with FinalIK is great idea to update :)



     
    Last edited: Feb 18, 2014
  42. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Guys, I’m under a serious problem with Unity’s Asset Store tools :/
    I have updates to push for all packages I share on Asset Store... But have no idea, it crashed and I can’t loggin anymore.
    I’m waiting on UT to solve this problem or tell me how to; I re-installed Unity, tried from another machine, nothing worked out. I hope I can fix this issue soon; sorry about this!



    Edit: Issue fixed by Asset Store team... Updated :)
     
    Last edited: Feb 20, 2014
  43. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hi new devs! I’ve got some emails pointing that the tutorial on guide.pdf is not working anymore;
    That is due to UT changed the “Hips” joint of the sample character to its “root” joint. Don’t know why they did that, but just assign back PELVIS to the Hips field on Mecanim’s Avatar configuration and that Character all good to go:



    Don’t forget to turn ON “IK Pass” on layers of the Mecanim controller as well!


    ——-


    Also, if you need help to use this with Final IK, please read this page: http://forum.unity3d.com/threads/22...im-Look-At-FABRIK-CCD-IK-BETA-RELEASED/page11
     
    Last edited: Feb 20, 2014
  44. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Somebody asked me about how would FP deal with stairs, so I’ve built this stair is few minutes to demonstrate that it is really simple.
    You just set your CharacterController/NavMeshAgent to ignore collision with stair-steps mesh and make foot-placement to raycast step-step’s layer.
    Is just that, stairs should be a “ramp” flat model with a stairs mesh on top of it. Do not use stair-steps as collision meshes:
    [video=youtube_share;66GV74-sdLg]http://youtu.be/66GV74-sdLg​
     
  45. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Nice! A step up in usefulness!

    (now we just need to get the feet from clipping and we're solid gold baby) :D

    -Steven
     
  46. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Yes, is kind of impossible to avoid that without animation/movement prediction.
    I’m studying algorithms to do that, kind of hard stuff.
     
  47. JaimeAriz12

    JaimeAriz12

    Joined:
    Mar 6, 2014
    Posts:
    28
    any chance of a webplayer?
     
  48. KrayonZA

    KrayonZA

    Joined:
    Mar 5, 2013
    Posts:
    52
    Hi There

    I'm having a slight problem with the foot placement for some reason when i enable the foot placement my UMA character legs go a little strange kinda like frog legs is there anything i could change in the FBFootPlacement script to adjust this?

    See screenshot below.

    $Screenshot.jpg
     
  49. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
    Hello NightShade2109;
    Foot placement aligns leg IK with the direction foot is pointing;
    See how character’s foot is pointing out instead of forward. That is why leg is opening like that; FinalIK is rotating the leg effector to the direction foot is pointing.
    You can edit the curves you use on the rotation weight, but doing so will affect floor alignment precision. If this is Fullbody IK you can also try to adjust L Thigh and R Thigh effectors to see if you achieve the results you need.

    But this issue may also be related to the way this character skin is rigged to the bones.
     
    Last edited: Mar 10, 2014
  50. KrayonZA

    KrayonZA

    Joined:
    Mar 5, 2013
    Posts:
    52
    Hi BrUnO XaVIeR

    Thanks for the feedback it should help point me in the right direction, ill play around with the curves and full body ik and see if i can get it right.