edited May 2018 in ORK Support
Hi again everyone,

I have a question.

How can I get a Mecanim animation to play based on whether an item is equipped in a particular equipment part?

There has to be a way I can set a parameter bool or int that can check that somehow. Does it have to be done with an on equip event, some kind of formula or a variable condition? I feel like it's right there somewhere, like most of my previous issues am I just overlooking it or overthinking it?

Note: I have weapons that can be equipped on either hand depending on the player's preference, so I can't simply set a parameter int based on weapon equip left vs right. I don't think. I dunno.
Post edited by flymolo on
  • Should the animation play when equipping it, or just use that animation while it's equipped in that part?
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • It'd be using that animation while it's equipped, and depending on what part it's equipped to (I've got sub-states for attack & idle inside the animations). So they'll be attached to each weapon individually.

    I think what I'll have to do is make it so that weapons can only be equipped on a main hand, and shields in the off hand, then make spells abilities instead of treating them like weapons to be equipped. That means being a full-on mage is going to be impossible because it'd be pointless to not have a weapon equipped at all times. I suppose I could have wands and spell books that house the spells, but then I'm right back to you're either a mage, or you're not (because I can't find a way to check what is equipped in a particular part beyond specific weapons or items).

    Anyways, I've gone through lots permutations of on equip events and parameters and keep running into problems when trying to equip multiple of the same type of weapon/spells in regards to animating the correct limb.

    Do you think I should wait until ORK 3 to try something like this GiL? You're always prompt with your replies and help, and I really appreciate it.


  • Hm, ORK's animation override system isn't ready for such a use yet, so you can't have different animations based on the equipment part the weapon is equipped on.

    You could do this in events, though - before playing the attack animation, check which weapon is equipped in which part and play the according animation.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • @flymolo - if you can show me how you have your Animator Controller set up, I can probably help you with this.

    The Combatant Animation step will play a Mecanim animation based on the parameters that you specified in the Animation Setttings --but you can set additional parameters on the Animator Controller outside of those settings. For example, you can place a Mecanim Animation step (Play Mode: None) before a Combatant Animation step to set additional parameters on the Animator. You may need to add a short (0.05s to 0.1s) Wait in between to ensure that the parameter is correctly set before starting the Combatant Animation.

    You may have looked at my Mecanim tutorial from a couple of years back. I really should bring that up to date, as while my general approach would stay the same, I would do a number of things differently now.

    I would still use the (int) WeaponType parameter, but I would go with a different spread of values to leave room for doing things exactly like what you're talking about. ;-)

    Something like:

    1000 One-Handed Melee Weapons
    2000 Two-Handed Melee Weapons
    3000 Ranged Weapons

    Then I might break that down further like this, with each weapon category representing a group of weapons that all use the same set of animations:

    1100 One-Handed Swords
    1200 One-Handed Axes
    1300 Daggers
    etc

    This allows me to use the final digit to distinguish between whether the weapon is equipped in the main hand (0) or in the off hand (1) -- or if you want to have a weapon that can be used either one-handed or two-handed, you can set the final digit to 2 for two-handed.

    Now, getting that value set on the Animator is going to take a bit of scripting (which I can help you with if you need it).

    I would create an Equipment Variable (float) on each weapon named "WeaponType" and set it to one of the values above (1100, 1200, etc). Rather than setting the WeaponType animator parameter in the Animation overrides, I would set it in the Equip and Unequip Game Events for each weapon. If you want to not only allow weapons to be equipped in either hand, but have two weapons equipped at once, then you'd need to add a "SecondaryWeaponType" parameter. I'd use the primary WeaponType to determine the locomotion and idle animations and just use the secondary one for attacks with the off-hand weapon.

    The (relatively) easy custom event node would get the WeaponType equipment variable from the weapon being equipped, check to see which Equipment Part it is equipped on, and then set the Animator's WeaponType parameter(s) accordingly (but add 1 if the weapon is equipped in the off hand).

    Setting the WeaponType when the weapon is equipped means that you would have to ensure that you're not relying on it to be set when the animation plays (don't use it in any of the override animation settings).

    We have an extra digit to play with in the WeaponType IDs, so we could probably do away with the SecondaryWeaponType parameter if we use a different convention:

    1xxx - general weapon type (one-handed melee, two-handed melee, ranged)
    x1xx - weapon animation type for the primary hand
    xx1x - weapon animation type for the secondary hand
    xxx1 - other data (direction of attack, the number of this attack in a sequence, a variation of an attack or damaged animation, etc)

    Thus:

    1100 - sword equipped in the main hand
    1010 - sword equipped in the off hand
    1120 - sword in the main hand, axe in the off hand
    1210 - axe in the main hand, sword in the off hand

    and so on. In this setup, perhaps a 9 in the second or third place represents a shield. Or you could just set a bool "Shield" parameter on the Animator.

    Anyway, I'm starting to go off on a bit of a tangent here, as I don't know how you have your animator set up. :-) Just floating some ideas about some approaches that would work. If you tell me more about your setup, I can help.

    Also, are you doing a turn-based or real-time game?

Sign In or Register to comment.