Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mecanim animated float wrap at 1f back to 0f

Discussion in 'Animation' started by AVOlight, Oct 20, 2015.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Code (CSharp):
    1. [Range(0f, 1f)] public float animatedRatio;
    Hoping someone knows a solution for using mecanim with ranged float values.
    e.g. 0.95f start value, animated To .25f, goes up to 1f wrapping round to 0f and up to .25f

    right now all i can think of is not using mecanim...
     
  2. Void24

    Void24

    Joined:
    Oct 15, 2013
    Posts:
    50
    When you pass your float to the animator, why not just modulate it into the range you need?

    SetFloat("animatedRatio", animatedRatio%1f);

    or if you don't want it going out of range even in your code, you can:

    animatedRatio=animatedRatio%1f;
    SetFloat("animatedRatio", animatedRatio);
     
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Thank you for the help,

    sorry i should have described more of my situation
    the value isn't a animator parameter
    its a value that is animated through mecanim key frames

    i'm using mecanim to store these key frames so that i can use the built in blend trees ( i use in direct mode )
    when i blend in a value, the interpolation doesn't know to wrap (and i have no idea how to tell it)

    without this ability, i just have make my own solution...
    ---
    representing the values as vectors should work
     
    Last edited: Oct 22, 2015