Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Suggestion - Mecanim params

Discussion in 'Animation' started by przemeknowaczyk, Mar 15, 2019.

  1. przemeknowaczyk

    przemeknowaczyk

    Joined:
    Mar 30, 2018
    Posts:
    6
    Lately, I've been using mecanim (and StateMachineBehavoiurs) as a simple state machine for gun logic - it really helps to prototype different behaviours, like firing with short bursts, burstin 'till your mag is empty at one click of mouse button, or shooting only if gatling gun is spinning at full throttle. Basically, it came out as a great tool for those purposes. However, I'd really could use some more comparison options in transition conditions. I'd really like to see "greater or equal" and "less or equal" options for int and float params. I know they are not necessery, but those would make things cleaner and easier to mantain.

    Let's consider following example. I'd like to make gatling gun, that will fire one type of projectiles until 90% of ammuinition is spent, and the other type after that. I can create param "bullets_reserve" which will take values from 0 (empty mag) to 1 (full mag). I don't want to specify arbitrary number of bullets since it can change quite often. Now i'm defining conditions:
    if bullets_reserve is less than 0.9 -> transition A
    if bullets_reserve is greater than 0.9 -> transition B

    The problem is, without hacky solutions like chaning 0.9 to 0.90001, I'm not able to cover whole spectrum of values, which will be a problem for 1000 rounds gun - it will just stuck after firing 900 bullets.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,579
    It's been a while since I've had to use Mecanim so it might have improved a bit from what I remember, but I always found the entire parameter and transition system to be terrible. You have to use the tedious UI to go through and set up all the transitions by hand, then at the end of the day you have a big mess of interconnected lines that makes refactoring a massive pain and still won't actually do anything without a script to control it. So you've got bits of logic arbitrarily separated between scripts and the state machine without any direct connection between them. Looking at a parameter in the AnimatorController won't tell you which script or scripts are controlling it, let alone what values they are assigning or when and why they think they need to set it. And conversely, looking at your script won't tell you if a parameter actually exists with the expected name or what range of values it expects.

    Even when I did still use Mecanim, I avoided parameters and transitions as much as possible. My AnimatorControllers had no transitions other than exit time transitions back to idle where appropriate. Then I just used CrossFade to transition to whichever state I wanted instead of setting a parameter and hoping everything was set up correctly.