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

Animation speed

Discussion in 'Scripting' started by htwarrior, Oct 10, 2006.

  1. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    Hi , I need to make the animation speed of my character independent of the frame rate. I have tried : animation["latigo3"].speed = Time.deltaTime; but my animation runs slower whe the frame rate is higher.


    Hope somebody could help me

    htwarrior
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    animation playback speed is already independent of frame rate thus, don't modify the animation speed variable at all and it will work fine.
     
  3. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    But I observe that my animations runs slower in when I have more frame rate.My models have a rigidbody attach with the isKinematic property checked and no gravity . My world has a scale of 1 and my models of 160 . Is this the problem?


    htwarrior
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Doesn't sound like that would cause a problem. Maybe some scripts still modify the playback speed? Maybe it just looks like it slows down, but it's really just a lower frame rate? By how much does it slow down?
     
  5. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    Hi, I need to modify the speed of the animation of my model proportional to its velocity.How can I do this in a frame independent way?

    thanks
    htwarrior
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Animation playback is always frame rate independent.

    To make it eg. twice as fast you write:
    Code (csharp):
    1.  
    2. animation["theAnimation"].speed = 2.0;
    3.  
    Code (csharp):
    1.  
    2. function Update ()
    3. {
    4.    var speed = rigidbody.velocity.magnitude;
    5.    animation["theAnimation"].speed = speed;
    6. }
    7.  
    The Mathf.InverseLerp function is a useful utility function for remapping speed. In the Character Animation example project there is also an example that modifies the playback speed of run / walk cycles for the character.
     
  7. htwarrior

    htwarrior

    Joined:
    Feb 25, 2006
    Posts:
    40
    Thanks I got the idea

    HTwarrior