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. Dismiss Notice

Help needed with player movement script and animations

Discussion in 'Scripting' started by dmarku26, Sep 4, 2020.

  1. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    Wondering if anyone has faced this issue before. I followed brackeys tutorial on 2d movement and animations and everything worked fine until i changed platform to mobile. Now my jump animation for some reason doesnt work all the time. Like out of 10 times, 8 time it will work and 2 times it will play running animation while jumping. I have no exit time on all animations and 0 transition time. I am wondering why sometimes the player plays run animation while jumping. I know without me providing the code is hard to understand but just wondering if someone has had this issue before when jumping animation randomly decides not to work. All other animations and transitions works fine (idle, run, crouch, attack). Switching from animation to another is perfect until jumping decides not to play. Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Brackeys does pretty good work, so this seems odd. One thing to check is to make sure you didn't use FixedUpdate() for a function that was supposed to be Update().

    FixedUpdate should only be used for physics. You should gather all input (touches, keypresses, clicks, etc.) in Update() and store them in local variables, then act on them in FixedUpdate().
     
  3. dmarku26

    dmarku26

    Joined:
    Aug 3, 2020
    Posts:
    23
    All inputs are gathered in the update. I have only one line of code in the fixed update like brackeys does in his tutorial. I cant paste the code as i am not home but i will do it when i get home.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    More directly useful to you would be to sprinkle
    Debug.Log()
    statements throughout the code.

    Doing this should help you answer these types of questions:

    - is this code even running when the jump fails? which parts are running? how often does it run?
    - is the fundamental input event being recognized and ignored? Or is it not even registering the input intent?
    - what are the values of the variables involved? Are they initialized? Are they different when the jump fails?

    Knowing this information will help you reason about the behavior you are seeing.