Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

mecanim "And" operator for conditions

Discussion in 'Animation' started by Tiny-Tree, Feb 10, 2015.

  1. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    I am trying to make a transition between my idle state and my locomotion blend tree. unit can move forward and backward, so +1 and -1 on my forward axis, i want to check if (Forward>01 && Forward <-0.1) we are moving. i have setup my condition like this but it return false every time, any idea ?
     

    Attached Files:

  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    (Forward > 0.1 && Forward < -0.1) is impossible, so of course it will always be false.
     
  3. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    do you mean is it impossible using mecanim ? i want to do something like this equivalent by scripting
    Code (CSharp):
    1. float onevar = 1;
    2.         if(onevar>0 && onevar<2)
    3.         Debug.Log ("true");
    so im checking if im moving forward or backward, its impossible with mecanim ?
    how should i handle this?
     
  4. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    In this example you are checking for a value between 0 and 2, but in your first example you're checking for the value to be both negative and positive at the same time, which never exists.

    Do you understand how the && operator works?

    Here is the link, if its unclear.
    https://msdn.microsoft.com/en-us/library/6a71f45d.aspx
     
  5. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,314
    i maybe typed too fast the example, i tried to do this:
    Code (CSharp):
    1.  
    2. public float speed = 0f;
    3.  
    4.         if (speed < 0.1f && speed > -0.1f)
    5.                         Debug.Log ("idle");
    6.         if(speed > 0.1f || speed < -0.1f)
    7.                         Debug.Log ("running");
    8.  
    On my problem was how to make the difference between OR and And, for the Or just had to add a second transition, so having two transitions of one parameter.
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    All of the transitions are considered individually in Mecanim so if you need greater control like that you might consider firing Events or maintaining Bool values in Mecanim from your code.

    Otherwise, I don't really see why you couldn't just feed the speed variable directly into Mecanim and setup transitions between states based on its value.
     
  7. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    You can add many condition on transition, all condition must be meet to trigger this transition which mean that they are handle with && operator
    transition.png

    if you want an or like operator '||' then you need to create different transition.