Search Unity

How to make the animation in same time as moviment?

Discussion in 'Scripting' started by lioncage, Sep 3, 2012.

  1. lioncage

    lioncage

    Joined:
    Nov 17, 2010
    Posts:
    108
    I'm using a code to make the character walk and animate at the same time, like this:

    Code (csharp):
    1.  
    2. public var gravity: float = 0.9;
    3. public var acceleration: float = 0.2;
    4. public var deceleration: float = 0.1;
    5. public var maxVelX: float = 1;
    6. public var maxVelZ: float = 1;
    7. public var alturaPulo: float = 12;
    8. private var controller: CharacterController;
    9. private var velocidadeX: float;
    10. private var velocidadeY: float;
    11. private var velocidadeZ: float;
    12.  
    13. private var character: GameObject;
    14.  
    15. function Start () {
    16. = GetComponent controller (CharacterController);
    17. }
    18.  
    19. function Update ()
    20.  
    21. if (Input.GetAxis ("Horizontal")> 0) {
    22. velocidadeX + = acceleration;
    23. character.animation.Play (); //Here is the main part in code, I would like to make the moviment
    24. //and the animation without the character stop in scene.
    25. }
    26. if (Input.GetAxis ("Horizontal") <0) {
    27. velocidadeX - = acceleration;
    28. character.animation.Play ();
    29. }
    30.  
    31. }
    32.  
    But it moves, stops moving, and animates.
    The wrong is that he can not stop moving to animate.
    It has to move and animate at the same time without stopped walking.
    How can I adapt this code this?
     
    Last edited: Sep 3, 2012
  2. lioncage

    lioncage

    Joined:
    Nov 17, 2010
    Posts:
    108
    I already find a way but seems like this.
    You have to create another object and put like children. This animation like children does not stop the main object.
    For now this is one good trick.
     
  3. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    Look into crossfade It will help animations transition from one to the other. I think your problem is your animation isn't looping..
     
  4. fano_linux

    fano_linux

    Joined:
    Jan 1, 2012
    Posts:
    909

    Take a look at my script so maybe it can help you. http://forum.unity3d.com/threads/141065-Character-Third-Person-Controller-(Portugues-brasil)
    are you brazilian?