Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Trigger Animation

Discussion in 'Editor & General Support' started by cgoran, Sep 15, 2005.

  1. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    Hey there. Trying to make a character walk animation tie into the FPS prefab.
    How do I get it to play an animation track on key down or other event?
     
  2. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    Best place to start is probably to check the "Character animation.unity" scene in the Examples project that ships with Unity.

    It gets installed in /Users/shared/Unity/Examples/Assets

    d.
     
  3. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    Well, that works. But how do I get a "walk cycle" to loop instead of just playing once.
     
  4. Darknes

    Darknes

    Joined:
    Sep 5, 2005
    Posts:
    21
    Maybe you could make a script like this (NOT TESTED, MAYBE IT WILL NOT WORK)

    Code (csharp):
    1.  
    2. function Update()
    3. {
    4.     while(Input.GetButtonDown("w"))
    5.     {
    6.         animation.Play("walk_forward");
    7.     }
    8. }
    9.  
    I assume that you want to make a character walk when you push a button. Right?
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    At the moment you just call:
    Code (csharp):
    1.  
    2. animation.Play ("name", AnimationPlayMode.Queue);
    3.  
    and call that several times.
     
  6. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    Ok! That loops the cycle, but how to make it stop on keyUp?
     
  7. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    file:///Applications/Unity/Documentation/ScriptReference/Animation.html#Stop

    Says:

    Code (csharp):
    1.  animation.Stop("walk_forward");
     
  8. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    yes, but if it's in a que it seems like it finishes whatever is in the que.....
    Hmmm.....
     
  9. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    also, looking through the reference, there does not appear to be an onKeyUp event? So I'm setting states. Or am I missing it?
     
  10. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    Well, if you are doing something like this (guessing on which function you were using):

    Code (csharp):
    1. if (Input.GetButtonDown ("Fire"))
    then you can just do:

    Code (csharp):
    1. if (!Input.GetButtonDown ("Fire"))
    (note the !)
     
  11. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    That isn't onKeyUp, I'm afraid. (!Input.GetButtonDown ("Fire")) is always going to be true except the one Update frame in which you press down the "Fire" button.

    As far as I know we're stuck with keeping track of the state through a private bool or something.

    -Jon
     
  12. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    indeed. Also don't seem to be able to stop the queued animations.
    Hmmm. seems like a walk cycle should be easy...
     
  13. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    So you want to remove everything from the queue so it plays until the end of current walk cycle animation and then stops?

    Right now there is no straightforward way to do that.
    You could store when you started the first queued walk cycle and find out when it will end, then stop exactly at that time.

    Code (csharp):
    1.  
    2. var timeSinceWalkStart = Time.time - timeWhenTheFirstWalkCycleStarted;
    3. var walkCycleEnd = Mathf.Repeat(timeSinceWalkStart, animation.GetClip("walk").length);
    4. yield WaitForSeconds(walkCycleEnd);
    5. animation.Stop("walk");
    6.  
    I do agree that should be easier.

    We are planning to allow for more fine grained control over animation with 1.2 or 1.3.
     
  14. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    But there are other ways to read input. Check Input.GetButton(). "Returns true if the virtual button identified by buttonName is held down."

    http://otee.dk/Documentation/ScriptReference/Input.html#GetButton

    d.
     
  15. cgoran

    cgoran

    Joined:
    Jun 11, 2005
    Posts:
    176
    Interesting. Really what I want to do is to set up game character movment. When the walk key is released, transition into the idel or jump animation from where the walk animation is at, without having to wait until the end of the walk cycle. There could be a second or two lag from the time the user presses the jump button to when the see the animation if you have to wait for the walk cycle to end.

    ALternativly,if there were a simple loop checkbox in the animation info window, then whenever I called another animation state it wou ld interupt the current animation with the new one.

    Or if there is another workaround for now? Or should I just wait until the next release to complete my game?
     
  16. Darknes

    Darknes

    Joined:
    Sep 5, 2005
    Posts:
    21