Search Unity

Motion Controller

Discussion in 'Assets and Asset Store' started by Tryz, Feb 21, 2014.

  1. hoodoo

    hoodoo

    Joined:
    Oct 19, 2012
    Posts:
    154
    Sorry for not answering earlier. I actually did find one state in WalkRunPivot_v2-SM without any motion. It's the "RunToIdle_RDown" state. I used the same motion that is assigned to the "RunToIdle_LDown" state. It's the RunToIdle_LDown animation. That was the only RunToIdle* animation I could find. But now the problem is not happening of course, so I'm happy! Am I missing anything in my copy of MC?
     
  2. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I looked in the project I use to submit to Unity and I see that the RunToIdle_LDown state does have the RunToIdle_LDown animation. So, I'm not sure why yours would be empty.

    Unfortunately, I don't know why it would be empty for you. :(
     
  3. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    When in doubt, re-install. It generally has a way of solving mysteries like this. ;)
     
    Tryz and TeagansDad like this.
  4. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    @FargleBargle - that's been my Windows mantra for the last 22 years.
     
    Tryz and FargleBargle like this.
  5. recon0303

    recon0303

    Joined:
    Apr 20, 2014
    Posts:
    1,634
    I personally like the Unity forums, that way all my assets are here, and I don't have to search for forums for all my assets, UGH...I have my own forum to worry about.. I personally won't buy an asset that don't have a Unity forums. That is just my opinion of course. So i'm glad we have one. Way easier to get a hold of Tim, and the community for issues, and we can help one another for advice. /Cheers.
     
    Tryz, FargleBargle and hoodoo like this.
  6. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I have a question about creating new motions. I have several different NPC monsters that all have different animations and slightly different animators, but the motions all use the same general logic: idle, walk/run, jump, basic attack. Should I be making a new version of each of the motions for each creature (OrcIdle.cs, OrcWalkRunPivot.cs, WolfIdle.cs, WolfWalkRunPivot.cs, etc...) or is there a way to just make basic motions like "MonsterIdle.cs" and then just switch out the animators and animations? Using MotionController's code auto-generation seems to hardcode the animation names and FBX paths into the code, but I don't know if that's necessary or just a helper for the editor gui.
     
    hopeful likes this.
  7. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    You're hitting on something me and a couple of people have been talking about.

    You're exactly right about the auto-generation code. It creates static variables that are hard to inherit from, but none of it is necessary. It's really just a helper if you're sharing motions.

    My suggestion would be to do something like the following:

    1. Create the general set of sub-state machines that you need: CreatureIdle-SM, CreatureWalkRunPivot-SM, CreatureJump-SM

    2. Create a set of motions where you can set the Phase IDs as a property in the inspector. These motions would understand the structure of your sub-state machines from #1. So, you'll have CreatureIdle.cs, CreatureWalkRunPivot.cs, and CreatureJump.cs.

    3. For each creature (orc, wolf, etc) you'll copy the sub-state machines, change the Phase IDs, and change the animations.

    4. For each creature, you would add the motions (CreatureIdle, CreatureWalkRunPivot, etc) to his motion list. Then, you would set the Phase ID to match the sub-state machines from #3 (orc, wolf, etc)

    That means your orc and wolf would technically both have a "Creature Idle" motion. However, you would set different Phase IDs for each and that would trigger the appropriate sub-state machine.

    I hope that makes sense.

    I actually plan on doing something like this, but you'll beat me to it. :)
     
  8. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    That mostly makes sense, but why do I need to change the Phase IDs? I assumed (maybe incorrectly) that the Phase IDs just had to be unique within the Animation Controller. So if the Orc's Idle and the Wolf's Idle both used Phase ID 100, it should be fine since I'm never going to have both the Orc Idle SubStateMachine and the Wolf Idle SubStateMachine in the same animator. Well, unless there are were-orcs. ;) Is this correct, or do PhaseIDs have to be unique across the entire project for some reason?
     
  9. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    It's really only the Phase IDs that come from Unity's "Any State" state.

    In all sub-state machines, there's an "Any State". Turns out unity treats this as a global state across all sub-state machines.

    So, if you have "Any State -> OrcWalkRunPivot-SM.Walk" and "Any State -> WolfWalkRunPivot-SM.Walk", they have to have different Phase IDs for the transition conditions or it will be random which one occurs. That's because the transitions come from the global "Any State".

    Inside of the sub-state machine, you're right. You can re-use Phase IDs.
     
  10. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    But if OrcWalkRunPivot-SM and WolfWalkRunPivot-SM are in two completely different Animators (one is Orc.controller attached to an orc, one is Wolf.controller attached to a wolf) then it shouldn't matter, right?
     
  11. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    You're right. I'm sorry.

    I'm so used to using the same animator for all my characters (goblins, orcs, humans... all 'humanoids'). If you're using totally different animators, you're right. In that case, the Phase IDs could be exactly the same... even from the Any State.

    Long day. ;)
     
    hopeful and makeshiftwings like this.
  12. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    @makeshiftwings I was just starting to explain what you meant. :) No, it doesn't matter if you're not sharing the animator controller among different creatures.

    You can swap out animations and adjust the transitions and it will all work fine. However, you are likely to run into problems if you add or remove any states or transitions AND the motion's code uses the auto generated code's static hashes for the state and transition IDd to detetmine when it is time to exit the motion. Also, don't accidentally recreate the animator state machine via script, or you'll lose your changes.

    Actually, that's an area where some additional functionality would be beneficial @Tryz. Being able to easily "export" an animator sub-state machine to script without being tied to a specific motion.

    I've currently got several such SSMs that are not strictly part of motions; currently I have animations running on the Upper Body, Left Hand, and Right Hand masked override layers, as well as on the Upper Body masked additive layer. The various weapon equip, store, and death motions send a parameter to the two hand layers to open and close the hands to match the rest of the weapon set animations (so the character keeps his hands closed when falling for example). These are semi-independent from the motions, so being able to quickly dump them to script and run the setup with the other Pack Methods would make it a lot easier to share.
     
    Tryz and makeshiftwings like this.
  13. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Ah, no problem, just wanted to make sure I wasn't missing something. There's a lot of code in the MotionContoller, I thought maybe it did some weird black magic somewhere and made a big merged list of all the SSM's in all the animators in the project or something. :)
     
    Tryz likes this.
  14. Catttdaddy

    Catttdaddy

    Joined:
    Mar 17, 2015
    Posts:
    55
    I am attempting to make my own weapon.
    After the weapon is drawn the character snaps back into the default idle position.
    This happens directly after he completes the unsheathnig animation and should transition into the weapons Idle.

    I have modified the PSS_EquipSword.cs

    It looks like this transition takes place in Update
    I understand this manages the flow of the animation as a whole

    Code (CSharp):
    1. public override void Update(float rDeltaTime, int rUpdateIndex)
    2.         {
    3.             mRotation = Quaternion.identity;
    4.  
    5.             // If we're dealing with mount points and inventories, we may need to
    6.             // attach the weapon at the appropriate time.
    7.             if (!mIsEquipped && mMotionLayer._AnimatorStateID == STATE_Spear_Unsheathing && mMotionLayer._AnimatorStateNormalizedTime > 0.25f)
    8.             {
    9.                 //GameObject lItem = CreateItem();
    10.                 //if (lItem != null) { mIsEquipped = true; }
    11.             }
    12.  
    13.             // Move to the true idle. We do this so IsActive stays true while we transition to PSS_Idle.IdlePose
    14.             if (mMotionLayer._AnimatorStateID == STATE_Spear_Idle && mMotionLayer._AnimatorTransitionID == 0)
    15.             {
    16.                 mMotionController.SetAnimatorMotionPhase(mMotionLayer._AnimatorLayerIndex, THS_Idle.PHASE_START, true);
    17.             }
    18.         }

    So from what I see, in order to get to my THS_Idle :
    The AnimatorStateID must be STATE_Spear_Idle and the AnimationTransitionID must be 0.


    How the AnimatorStateID is set is a bit of a mystery to me. I don't see it being set anywhere in the code.
    Im also not sure about the AnimationTransitionID being 0. I assume this is a bool and if the AnimationTransitionID is 0 the transition is completed.
    I do have in the autogenerated code:
     
  15. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi again,

    I'm trying to get a good top down shooter controller. I'm really happy with motion controoler and now i'm trying to get an aiming motion in layer 1 for a masked upper body. Could you give me a good start point to do that? i'm just replacing the animations with the apistol animset, but i need to controll the layer 1 weight to enable or disable based on the current state.

    Thanks!
     
  16. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Looks like my response was deleted... maybe during their maintenance last night.

    What's probably missing is the setting of the ActorControler.Stance. I use this to determine the mode or stance the actor is in and hit helps manage what motions activate.

    For example, in the PSS_EquipSword's Activate() function you'll see this:
    Code (CSharp):
    1. mActorController.State.Stance = EnumControllerStance.COMBAT_MELEE_SWORD_SHIELD;
    Now, other motions like PSS_Idle will check this to determine if they should go into the sword & shield idle vs the default idle. You'll see that in the TestActivate() functions.

    With something like "Ax and Shield" or "Hammer and Shield", you would be able to use all the Sword & Shield animations. So, the PSS_Idle motion would work fine. My guess is that with something like a spear, you'll need different motions because all your animations are different.

    In this case, you'd probably create a Spear_Idle, Spear_EquipSpear, etc. Then, you'd set the stance to a value that represents your spear.

    You shouldn't have to force any idle as the motions will handle that automatically.

    The AnimatorStateID is set because of the SetAnimatorMotionPhase() function. The result finally gets set in the animator through the MC's SetAnimatorProperties() function.

    I hope that all makes sense.
     
  17. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    The MC controls animator layers through it's motion layers. So...
    MC layer 1 controls animator layer 1
    MC layer 2 controls animator layer 2
    etc.

    When you look at my default Humanoid animator controller, you'll see parameters like L0MotionPhase, L1MotionPhase, etc. The "L0", "L1", "L2", etc... controls the corresponding animator layer.

    So, your top down shooter would live on two layers. Motion layer 1 would have motions for movement and motion layer 2 would have the aiming. That aiming would be a totally separate motion that works regardless if the motion on the first layer is idle, walk, jump, etc. Motions on layer 2 probably wouldn't have any movement associated with them.

    A good example is my Punch motion tutorial in the user guide (page 37):
    http://www.ootii.com/Unity/MotionController/MC2Guide.pdf

    The flow I talk about in the Motion Builder's Guide (page 11) occurs for each layer:
    http://www.ootii.com/unity/motioncontroller/MCMotionBuilder.pdf
     
    TeagansDad and Danirey like this.
  18. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    @Tryz is there an easy way to allow some L0 motions to interrupt an L1 motion without hard coding it?

    For example, I'm building a set of motions for Pistol Animset Pro. I have the Shoot motion on L6, which is an additive layer with an upper body mask. I want it to play on top of some motions (Idle, WalkRunX, crouching idle and walk motions, etc) but I want it to be interrupted by others (Damaged, Death, Store, Equip a different weapon, the generic Jump, Clim 0.5m, et ). Likewise I've got an alternative sword attack motion on a masked override layer that is used if attacking while strafing (instead of stopping the left\right movement and playing the usual attack and step forward animation).
     
  19. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Only by activating a motion on L1.

    Think of each layer as separate threads that run independently. So L0 doesn't know anything about L1, L1 doesn't know anything about L0, etc. That means L0 can't really interrupt L1. What it can do is activate a motion on L1 that can then interrupt the current motion on L1.

    In your first example, it's so specific that some of your motions would interrupt L6 and some don't; I'm not sure how I would make that generic for everyone. The best way to do this may be with a separate component who listens for motion events either on the Motion Controller (MotionActivated) or on specific motions (OnActivatedEvent and OnDeactivatedEvent). The handler would interrupt L6 as needed.

    This new component would be pretty simple as it's really just a matter of assigning a handler and putting your custom logic there.

    Here's a quick example of what I mean:
    Code (CSharp):
    1. using UnityEngine;
    2. using com.ootii.Actors.AnimationControllers;
    3.  
    4. namespace com.ootii.Demos
    5. {
    6.     public class MCLayerHandler : MonoBehaviour
    7.     {
    8.         private MotionController mMC = null;
    9.  
    10.         private void Start()
    11.         {
    12.             mMC = gameObject.GetComponent<MotionController>();
    13.             mMC.MotionActivated = OnMotionActivated;
    14.         }
    15.  
    16.         private void OnMotionActivated(int rLayer, MotionControllerMotion rNewMotion, MotionControllerMotion rOldMotion)
    17.         {
    18.             if (rLayer == 0 && rNewMotion.GetType() == typeof(Jump))
    19.             {
    20.                 MotionControllerMotion lL6Idle = mMC.GetMotion<Idle>(6);
    21.                 mMC.ActivateMotion(lL6Idle);
    22.             }
    23.         }
    24.     }
    25. }
     
    Last edited: May 1, 2017
    hopeful and TeagansDad like this.
  20. Manourer

    Manourer

    Joined:
    May 1, 2017
    Posts:
    2
    Hello, I just bought your asset, is it possible to swap the default walk or run animations simply ? Thank you.
     
  21. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hi @Manourer ,

    The MC includes several walk styles: WalkRunPivot, WalkRunStrafe, and WalkRunRotate. This way you can choose your movement style.

    Each of these styles has an associated animator sub-state machine WakRunPivot_v2-SM, WalkRunStrafe_v2-SM, and WalkRunRotate_v2-SM. These sub-state machines are just standard mecanim sub-state machines that hold the animations.

    If your animations line up with the ones I use in the WalkRunX_v2-SM sub-state machine you care about, yes. You would just replace my walk animation with your walk animation inside the sub-state machine. This is just standard Unity mecanim work.

    If your animations don't line up (maybe you start on the left foot and I start on the right), then you would have to do some tweaking of the sub-state machine.

    (I never know what people's experience level is with Unity. So, I'm hoping you know what Unity's Mecanim and sub-state machines are. :) )
     
  22. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Woo, finally got creature motions working! The "waking up" animation is actually the plantagonist equipping an invisible "sword" with the wake as the equip motion, and it uses the sword and shield pack's basic attack system to do different attacks. I have to say, Tryz, I am loving the Motion Controller. I was originally using UFPS's third person controller for monsters and it had become a nightmare; things have been much smoother since I made the switch to Motion Controller. :)

    plantagonist.gif
     
  23. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
  24. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    hahah... I love it. :)

    The goal with each of these packs is a foundation. So, you're doing it exactly right. :)

    Thank you so much. That's great to hear. There's lots more coming and seeing your little video just helps to motivate me. I feel like I'm part of everyone's game. :D

    Now when people ask if you can use the MC with other things besides humans, I can add plants to my list! hahaha
     
    TeagansDad and makeshiftwings like this.
  25. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    Snake people, too.
     
    recon0303 and Tryz like this.
  26. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    haha... Yes!
     
  27. Manourer

    Manourer

    Joined:
    May 1, 2017
    Posts:
    2
    Thanks for the fast answer! I'm totally a beginner with Mecanim, I'm trying to use mixamo animations with my own models. I'll tell you when it's working.
     
    Tryz likes this.
  28. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hey thanks.

    I'm following the step by step motion creation guide, and i have an aiming layer working. Now my question is, How can i controll the weight of that layer? let's say that i will have only one animation for aiming and all the other animations will be in the L0 for the other stuff. In some states i'll have to deactivate that layer(maybe through the weight or maybe enabling or disabling in MC. What do you suggest to use?


    Thanks a lot for the help.
     
  29. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    That's what I figured would be the case. Doesn't hurt to ask though. ;)

    I am definitely starting to see more and more of a need for an easier way to manage the complexity of a large set of animations, especially when multiple layers are involved.

    I'm running into limitations of the ActorController stances as well. I mean, sure I can keep adding a virtually unlimited number of stances... But I can see it getting clunky in short order. I've started extending the base list of stances:

    Code (CSharp):
    1. public class ExtendedEnumControllerStance : EnumControllerStance
    2.     {
    3.         public const int COMBAT_MELEE_TWO_HANDED_SWORD = 15;
    4.         public const int COMBAT_MELEE_SWORD = 16;
    5.         public const int COMBAT_RANGED_PISTOL = 17;
    6.  
    7.         /// <summary>
    8.         /// Friendly name of the type
    9.         /// </summary>
    10.         public static new string[] Names = new string[] {
    11.             "Traversal",
    12.             "Combat-Melee",
    13.             "Combat-Ranged",
    14.             "Swimming",
    15.             "Stealth",
    16.             "Climb-Crouch",
    17.             "Climb-Ladder",
    18.             "Climb-Wall",
    19.             "Spell Casting",
    20.             "Channeling",
    21.             "Combat-Ranged (longbow)",
    22.             "Combat-Melee (sword and shield)",
    23.             "Levitation",
    24.             "Flight",
    25.             "Unconscious",
    26.             "Combat-Melee (two-handed sword)",
    27.             "Combat-Melee (one-handed sword)"
    28.             "Combat-Ranged (pistol)"          
    29.         };
    30.     }
    Aesthetically, it bugs me that the combat stances aren't together, but that's a relatively minor thing. I've been looking at adding the "crouch" animations (possibly as stealth animations as well), but the question is how to handle all of the crouch plus weapon stances? Pistol Animset Pro has animations holding the pistol while in a crouch, but other weapons will generally need to have upper body idle and attack animations playing on a masked layer. So does that mean that IK should add a stance for every crouch plus weapon combination? There could conceivably be other (mode of movement) plus (weapon) combinations (such as flying and attacking with the sword, with a bow, etc). Perhaps the Weapon Sets could be extracted from the stance and moved into a separate value? That might make it easier to manage combinations of stances that represent different modes of movement (walking or "Traversal", swimming, crouching/sneaking, climbing, flying, etc) with stances that represent how different weapons are held.

    I haven't thought this out super well... Just tossing out ideas as they come to me. ;)
     
    Tryz and Danirey like this.
  30. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @Danirey ,

    That really goes along with my response to @TeagansDad dad about 11 posts up. The one where I put the code.

    You would probably have an "Idle" motion on L1 and then trigger that when you no longer need to the aiming to work on L1. Any kind of blending in or out would be done in your motions.
     
    TeagansDad and Danirey like this.
  31. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    All of this is has been an evolution of features over time. So, I'm happy to keep evolving into something better.

    Some thoughts:
    Any time we deal with an undetermined list of items, it's going to get out of order. If I go with true Enums, it doesn't allow others to expand it and removes the simplicity of the underlying "int".

    I could probably come up with some dynamic list where you enter all the values yourself, but I'd still have to lock down my values or my "Combat Melee" ID would be different for everyone and not usable across the board.

    InventoryPro has an interesting approach where there are some fixed IDs and you can add more through their setup. However, it requires a "database" and it all felt pretty confusing to setup.

    I like the simplicity and expandability of the "int" approach.

    Extracting out the idea of "Upper Stance" and "Lower Stance" or "Movement Stance" and "Combat Stance" (as you suggest) could work too.

    In this case, I'd probably move the stance out of the AC to make sure there is no confusion. The AC never uses it anyway.

    In the end, we'll always end up with the aesthetic issue for an undetermined list. I'm definitely open to other ideas that help everyone.

    [EDIT]
    Another option is multiple stances that are List<string> instead of int[]. Programming purists will hate that, but it does allow others to change the items and order while still keeping the individual meanings.
     
    Last edited: May 2, 2017
    TeagansDad and Dwight_Everhart like this.
  32. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Another quick update on the Spell Casting Motion Pack



    I try to work on it a couple of days a week. So, it's going slow, but it is going. :)
     
    Weblox, FargleBargle, hopeful and 3 others like this.
  33. Dwight_Everhart

    Dwight_Everhart

    Joined:
    May 11, 2014
    Posts:
    123
    @Tryz I agree with you not including a UI with the motion packs. There are many UI assets available, and each game has unique UI needs.
     
    TeagansDad and Tryz like this.
  34. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    The stance is basically determined by the current motion, right? You could get rid of stance entirely and instead add a "Tags" field to MotionControllerMotion (a List<string> would be fine, a HashSet<string> would be better, almost as fast as checking ints) . Then the user could put a list of tags on their motion, like "COMBAT_MELEE,HAS_SWORD,HAS_SHIELD,IS_FLYING", and instead of looking for a stance, the other motions would just check the tags of the current motion: if(rPrevMotion.HasTag("COMBAT_MELEE")) { //activate }

    HashSet: https://msdn.microsoft.com/en-us/library/bb359438(v=vs.110).aspx
     
    Tryz likes this.
  35. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Think of it more like determining the current motion set. So, when you equip the sword & shield, the stance is set to COMBAT_MELEE_SWORD_SHIELD.

    Now the MC knows to use the "Sword Shield Idle" instead of "Bow Idle" or "Spell Idle".

    That said, your approach is still interesting. The challenge would be something like "Climb Crouch" that could be valid for both sword & shield as well as bow. When coming out of Climb Crouch (which has both tags) which idle do we go to?
     
  36. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    Ah yeah I didn't think about that. I think in that case having a separate way to track it makes sense, but I agree it should be separated from ActorController. I feel like the most "correct" way might be to just add separate small components (optionally with interfaces so users could overwrite/combine them) like:
    Code (csharp):
    1. public class SwordShieldTracker : MonoBehaviour, ISwordTracker, IShieldTracker {
    2.     public bool IsSwordEquipped { get; set; }
    3.     public bool IsShieldEquipped { get; set; }
    4. }
    5.  
    6. public class FlyingTracker : MonoBehaviour, IFlyingTracker {
    7.     public bool IsFlying { get; set; }
    8. }
    9.  
    10. public class SomeMotion : MotionClassMotion {
    11.     public override bool TestActivate() {
    12.         var swordTracker = GetComponent<ISwordTracker>();
    13.         if (swordTracker != null && swordTracker.IsSwordEquipped) { //Do the thing }
    14.     }
    15. }
    But I can see how you might not want a bunch of separate components as it can look messy. A different option:

    Code (csharp):
    1. public class StanceTracker : MonoBehaviour {
    2.     private HashSet<string> activeStances = new HashSet<string>();
    3.  
    4.     public void ActivateStance(string stance) { if (!activeStances.Contains(stance) activeStances.Add(stance); }
    5.     public void DeactivateStance(string stance { if activeStances.Contains(stance) activeStances.Remove(stance); }
    6.     public bool IsStanceActive(string stance) { return activeStances.Contains(stance); }
    7. }
    Then you can have multiple stances active at once and motions have a central place to check to see if a stance is active.
     
    Tryz likes this.
  37. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I like that. I need to chew on it some, but that may be a good idea.

    Yesterday 1 stance worked, today we need 2, and I'm guessing we'll need 3+ soon enough.
     
    TeagansDad and makeshiftwings like this.
  38. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    That could be one way to implement weapon & shield versus just wielding a one-handed weapon without treating "Sword" as a distinct entity from "Sword & Shield" in all cases. Or for performing spellcasting while crouching with a one-handed weapon. ;)
     
    Tryz likes this.
  39. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Update day!

    I've just submitted some updates to the assets. There are a couple of bug fixes, but nothing critical.

    Don't feel compelled to update. If you do, you can import on top of your existing project.

    IAttributeSource
    For those of you that have created your own Attribute Sources, there's a big change there. The IAttributeSource has some new functions that you'll need to implement. It won't be hard, but don't be surprised.

    Since IAttributeSource now supports multiple attribute types, I changed functions like this:
    Code (CSharp):
    1. public T GetAttributeValue<T>(string rAttributeID)
    As always, I'm here to help.
     
    twda, acaroppos and TeagansDad like this.
  40. Xialya

    Xialya

    Joined:
    Oct 4, 2015
    Posts:
    52
    Thanks for the help, Tim, with the transitions issue, it's working fine now. :)

    I still have an issue that I need to pinpoint because it's sometimes happening continuously, sometimes not at all or occasionally. Based on the animator, at the end of some animations it exits to Idle (not even the sword idle; the very basic one). It started to happen after I had replaced the motions by those I bought from Kubold. (The sales were really killing my budget...). Although I cannot be 100% sure.
    I'll have a deeper look and make a video to show you.

    Today I was able to link my spell casting system with the motion controller (KryptoFX's effects were all too tempting..).
    Here's a video to showcase a bit. :)
     
    TeagansDad, Dwight_Everhart and Tryz like this.
  41. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    @Xialya - did you add or remove any states or transitions in your animator state machines?

    Which of Kubold's packs are you using? I've got sets of motions in development for most of them. If you want to help test them before I share them publicly, I can pass them on to you. (That offer goes out to everyone here too; PM me if you want access to in-development versions)
     
  42. Xialya

    Xialya

    Joined:
    Oct 4, 2015
    Posts:
    52
    I've got Sword and Shield, and One-Handed Sword. ...And waiting for the release of the Longsword...
    I'd gladly help testing.

    I added a couple of sub-state machines for the motions I was creating. I was also altering the original transitions and deleting some unneeded ones.
     
  43. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Hey @Xialya , that looks great! :D

    If you added or removed states from my sub-state machines, you'll need to re-auto-generate the code. That's because I have logic in the code that determines if the current mecanim state matches a state the motion knows about. If you are in a state the motion doesn't know about it will think you're in the wrong motion and stop it.

    I wouldn't think that would take you back to the basic idle, but it may be something to check.

    If you're dealing with your own states, you may want to make sure any ending idle is the idle that matches your stance.

    Without looking at the code or animator changes you've made, I'm not really sure. It's not something that I've seen just happen. o_O
     
  44. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    957
    @Xialya - if you add or delete states and/or transitions without regenerating the auo-generated script code for the motion, you can end up with motions that exit before they are supposed to, as some of the checks in TestUpdate will make use of that code.

    EDIT: Ninja'd by @Tryz.

    I'll see about getting them packaged up for you in a day or so. I just restructured my animator to use 7 layers (like a dip!) To allow for masking the upper body, individual arms, hanfs, etc. So I just want to make sure it's all stable.
     
  45. Xialya

    Xialya

    Joined:
    Oct 4, 2015
    Posts:
    52
    I think I got it all wrong when creating my motions. :/
    I was being too fast.

    I'm going to have a further look at the documentation and re-do everything.

    @TeagansDad No problems! :)

    So, basically, what I had done was:
    - Change the name of the animator states under the PSS_BasicAttacks-SM substate machine to Combat High 0, Combat Med 1, etc...
    - On the Motion Controller, I edited the name of each Attack Style to match the name of their corresponding animator state.
    - Then I edited PSS_BasicAttack.cs to replace the original names for the transitions and states by my new ones.

    After that, every character and NPC had the same BasicAttack motion, and I just had to change the animations in their own Animator Controller for their specific attacks and moves.

    But I guess it was the wrong way of doing it. '^^

    How should it be done properly?
    I was just re-reading the documentation, and I'm a bit confused.
    How can I add new motions that links to a specific BasicAttacks script?

    Is there a way that I can add a pack of extra motions like for one-handed weapons, spears, monster specific attack, etc so I can just make a big animator controller with all attack styles inside and switch to one another, like going from a Sword and Shield stance to a One-Handed stance after putting down a shield, or to a Spear stance after grabbing one?

    Would it be like creating an overriding Layer in the animator for each combat style and somehow tell the Motion Controller to only look into that specific layer?
     
    Last edited: May 3, 2017
  46. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    There's nothing wrong with doing that. However, by changing the state names you've given them a new "address". If you don't auto-generate the code, those new addresses won't match the addresses that my old auto-generated code expects.

    I talk about auto-generating code in the Motion Builder's guide (page 18). Hopefully that helps.
    http://www.ootii.com/unity/motioncontroller/MCMotionBuilder.pdf


    Lets step back for a second...

    Typically attacks are made up of a lot more animations than simply "swing". Lets take the difference between "sword and shield" and a "staff". Its not just that the swing animation is different. The idle animation is different, the walk is different, the block is different, equipping the weapon is different, even a jump can be different. Lets call these groups of animations stances.

    Fortunately, there are some weapons that can share a stance. For example, "ax and shield" is probably the same as "sword and shield" or "hammer and shield".

    With that in mind, there's now two ways of thinking about using different weapons:

    1. Can this new weapon use an existing stance?

    2. Does this new weapon require a new stance?

    In the case of #1, let's assume you're talking about "ax and shield". It can use the "sword and shield" animations, animator sub-state machines, and the PSS_Motions. In this case, you're just using the weapon sets in the Basic Inventory to instantiate an ax instead of a sword. Everything works... simple. I talk about this in the Sword & Shield Motion Pack user's guide.

    In the case of #2, it's not that easy. A staff needs different animations and is a different stance. In the case of the MC, that means different motions and different sub-state machines.

    So, this is really a matter of copying the PSS_X motions and the PSS_X-SM sub-state machines and tweaking the states and the transitions to fit your new animations. Everything works the same, but you have a totally different stance (think a new motion pack).

    With this approach, you may have the follow motions:
    Staff_Idle, Staff_WalkRunPivot, Staff_BasicAttacks, Staff_BasicBlocks, Staff_Equip, etc.

    With this approach, you may have the following sub-state machines:
    Staff_Idle-SM, Staff_WalkRunPivot-SM, etc.

    The weapon sets would still be used to activate the right "equip" motion. That will play the right animation and set the right stance.

    So, with all that... that's what I did with "Sword & Shield Motion Pack". It's really "XXX and Shield Motion Pack". What you, I, or others can do is use that as a template for creating "Staff Motion Pack", "2 Handed Weapon Motion Pack", etc.

    All the underlying systems are coming into place because we just started with "XXX and shield"... inventory, attributes, damage flow, death flow, etc.

    Behind the scenes...
    If you think about what I've been doing, I created a base character controller (AC), animation controller (MC), ranged foundation (Archery), melee foundation (Sword & Shield), magic foundation (Spell Casting), etc. Each of these are to ensure a good Action Adventure RPG foundation exits. With this foundation, we can then expand out each of the systems... ranged, melee, magic, inventory, attributes, etc.

    Whew. I hope that all makes sense.

    [EDIT]
    Personally, I don't like giant animators that have every possible weapon linked. I know that can look cleaner, but it's less modular and doesn't expand well for things beyond basic attacks. We can make it so every weapon has attack #1, #2, and #3. But, what if I want the sword to do way more than just #1? This is why I like the sub-state machine approach.

    You can certainly create motions that work with a giant animator, but that isn't really how my brain works. :D
     
    Last edited: May 3, 2017
    TeagansDad likes this.
  47. Xialya

    Xialya

    Joined:
    Oct 4, 2015
    Posts:
    52
    Thank you for the explanation.

    Based on that I had a further look at the motions and the related scripts.
    I noticed that the weapon inside the inventory defines the equip motion, the equip motion defines the stance.
    But I'm lost after that.

    So I could have a character initially equipped with sword and shield pick up a staff, which when pressing the equip input will trigger a Simple Motion with a staff-equipping animation and an animation event that changes the stance to a Staff-stance that I would have added to EnumControllerStance.cs?

    I miss some important parts which block me from understanding everything.
    Is it possible to create a motion like PSS_EquipSword for the staff instead of using a Simple Motion? (I would copy-rename and change the stance, or keep the original but add a field to select the stance).
    Is there a list/enum somewhere to add any custom-created motion?
    **EDIT** I just found out... I forgot to change the name of the created motion. Now it appears in the list!

    After the change of stance, how does the MC know which one between PSS_Idle and Staff_Idle to use, or attack, move, etc?

    If a character has different stances (sword and shield, staff, two-handed weapon, spear, magic, bow). What would you recommend about the Animator?
    Add all sub-state machines on the same layer?
     
    Last edited: May 3, 2017
  48. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    No. This is all beyond what "Simple Motion" is for. Don't think about that. ;)

    This is the conversation we're having on the forums now about stances. :)

    The way it works today is that each of the motions looks at the AC.Stance value to determine if it should start:
    PSS_Idle won't start unless the stance == COMBAT_MELEE_SWORD_SHIELD
    Bow_Idle won't start unless the stance == COMBAT_RANGED_LONGBOW
    Idle is the default... so, if nothing else is running it will start.

    This is how the MC works using each motion's TestActivate() function.

    Yes. Exactly. There are a couple of other things to change... like the Phase ID, but this is the right idea.

    You would have a "Staff_Equip" motion that is very close to the "PSS_EquipSword" motion.

    Because most motions look at the stance in the TestActivate() function. This way a 'staff' motion won't activate if you're in the 'sword & shield' stance.

    Correct. All these full-body animations exist in the same layer (Base Layer) of the animator. If you look at the animator after importing my packs, you'll see Idle-SM, PSS_Idle-SM, Bow_Idle-SM, PMP_idle-SM (for magic), etc.

    The animator layer can get hairy with all the sub-state machines, but no different than if you have a sub-state machine with lots of states. I just try to lay them out neatly. What's nice about this approach is that you can modify a sub-state machine (say staff) without affecting any other (say sword & shield). Each sub-state machine is its own little silo.

    If you're expanding things as it sounds like you are, first make sure you understand the general motion flow:
    http://www.ootii.com/unity/motioncontroller/MCMotionBuilder.pdf (page 11)

    Then, make sure you understand the sword & shield motion flow:
    http://www.ootii.com/Unity/MotionControllerPacks/SwordShield/SwordShieldUsersGuide.pdf (page 6)

    When I'm done with the Spell Casting Motion Pack, I'll create a diagram of how things like Basic Inventory and Basic Attributes fit in. The information is in the documentation, but a picture may help.

    [EDIT]
    I should add...

    Today AC.Stance is just an 'int'. It can be anything you want. In the EnumControllerStance, I have default ones that I use in the packs. You can expand that or just hard-code an int. Stance is just an 'int' that is set by some motion (say Staff_Equip) and looked at by others (say Staff_Idle).
     
  49. twda

    twda

    Joined:
    Oct 25, 2012
    Posts:
    111
    @Tryz Do you know if ICE Creature Control can easily be combined with your MC?
     
  50. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    Unfortunately, I don't know.

    I own it. I just haven't had time to crack it open.