Search Unity

2d Animation not working correctly

Discussion in 'Scripting' started by MrZeker, Jun 27, 2019.

Thread Status:
Not open for further replies.
  1. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    Hello
    i need to move an image from point A to point B. i wanted to make it smooth, so im using animations (so i can move in another directions later on if needed or in no-straight-lines manners).
    the problem is: i play the animation and it starts and ends almost instantly, moving only 10% of what it should.
    Code (csharp):
    1.  
    2.  
    3.         Animator animm = PlayerCharIMG.GetComponentInChildren<Animator>();
    4.         Debug.Log("TEST1");
    5.         animm.Play("Arcade1");
    6.  
    This si the code, it is in a public function that i trigger with a button.

    The animation was created in unity, with the animation tool. If i check the animation tool and put play, it works perfetly, but it doesn't in-game. I attached the animation controller to the image itself. (the gameobject that should be moving). And the animation is obviously put in the animator.
    Any ideas how to fix this?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Are there any outgoing transitions in the animator? May be some condition activates a transition and animation finishes? Also in Unity the animator controller visualises it's state in realtime during playmode. Try to dd Debug.Break in your function, start the game, wait till it pauses on debug.break, bring up the animator and analyze step by step what's going on with your animation. It will highlight currently playing state and/or transition.
     
  3. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    This is what i get, the animation starts, but it instantly stops. this seems to be happening with the base animation. (ArcadeTowerAnim), however that one doenst move, its just a static place to use as a basis so i cant reallly tell.



     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    Maybe another script stopping the animator? Test it with new empty project
     
  5. MrZeker

    MrZeker

    Joined:
    Nov 23, 2018
    Posts:
    227
    yeah, that was the solution, i dont know why but the timescale is set to 0 on the start, so i have to manually turn to 1 on every different scene, im still trying to figure out why it is happening.
    thanks for the help!
     
  6. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    You can search "Time.timeScale through all your solution files to find out who's messed up with time.
     
  7. aaliya710

    aaliya710

    Joined:
    Nov 18, 2021
    Posts:
    1
    Hi,iam working in unity2d and i have succesfully completed implementing runner game using keys.now iam working on joystick feature so i have used UI buttons to simulate the arrow keys functionality the character moves but it isn't animating what shall i do?
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,486
    There's a dedicated 2D forum. Please don't hijack/necro old threads to discuss it. Just post on the 2D forum with your issue where someone should help you.
     
Thread Status:
Not open for further replies.