Search Unity

2d Animation

Discussion in '2D' started by RunOrDi33, Oct 15, 2020.

  1. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    Hello everyone , I'm creating a among us game and i have created 2x animations idle and run .. the problem is when i press play i find that 2x animations works together when i move and the run animation under idle animation.. check the photo .. i don't know whats wrong !
     

    Attached Files:

  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Have you checked the animator to make sure the transitions are set up properly?
     
  3. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    here it is and the source is
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class CharacterController : MonoBehaviour
    7. {
    8.  
    9.     Rigidbody RB;
    10.     Transform Player;
    11.     [SerializeField] InputAction WASD;
    12.     Vector2 movementInput;
    13.     [SerializeField] float moveSpeed;
    14.     Animator Anim;
    15.  
    16.     private void OnEnable()
    17.     {
    18.         WASD.Enable();
    19.     }
    20.  
    21.     private void OnDisable()
    22.     {
    23.         WASD.Disable();
    24.     }
    25.  
    26.     void Start()
    27.     {
    28.         RB = GetComponent<Rigidbody>();
    29.         Player = transform.GetChild(0);
    30.         Anim = GetComponent<Animator>();
    31.     }
    32.  
    33.     void Update()
    34.     {
    35.         movementInput = WASD.ReadValue<Vector2>();
    36.         if(movementInput.x != 0)
    37.         {
    38.             Player.localScale = new Vector2(Mathf.Sign(movementInput.x), 1);
    39.         }
    40.  
    41.         Anim.SetFloat("Speed", movementInput.magnitude);
    42.     }
    43.  
    44.     private void FixedUpdate()
    45.     {
    46.         RB.velocity = movementInput * moveSpeed;
    47.     }
    48. }
     

    Attached Files:

  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Maybe I am misunderstanding your issue. Are you saying that both the Idle and Run animations are occuring at the same time? Your first image is unclear to me
     
  5. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    yes , Idle is above run when i move or testing the animation before i try in game mode.. check the video
     
    Last edited: Oct 16, 2020
  6. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Ooooh okay that appears to make sense to me now. When you were on the Run animation in the animation window, it looked like you had two sprites on top of each other. So go into the animation for run and make sure that only one sprite is on each frame. If that isnt clicking with you, i would just remake your run animation and make sure you are only putting one Run sprite at each frame. Recreating the run animation should take less than 2 minutes since it appears to be 5 sprites or less.
     
  7. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    i remade it with only 1 sprite each frame , im sure about that and i still have the problem... check the photos
     

    Attached Files:

  8. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    That is bizarre. Maybe redo your transitions in the Animator window. Also, press play and look at the Animator window to see which animation is technically running. I am not sure what it is but i think its purely an issue with the Animator and your transitions, you might just have to mess around with them. I wish i could be more help.
     
  9. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    thanks for trying to help me brother , maybe i will change my unity to 2020 , because im sure nothing wrong :(
     
  10. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Ehh, before you try that, just make a new scene, a new animator and new animations. In my opinion that is easier than installing a different version
     
  11. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    alright , i will make a new project
     
  12. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    i made a new one and i still get the problem and i dunno why its happen :(
     
  13. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    What is the Animator condition for the Idle transition to occur? Speed < 0.1f or something?
     
  14. RunOrDi33

    RunOrDi33

    Joined:
    Mar 15, 2019
    Posts:
    42
    yes , check the photos
     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      170.5 KB
      Views:
      289
    • 2.jpg
      2.jpg
      File size:
      173.4 KB
      Views:
      287
  15. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Hmmm very weird as it seems everything is set up properly. Looking at your code more, maybe it has something to do with your Vector2 movementSpeed and using magnitude. Im sorry I havent been any help. If it still doesnt work, id try to rework your movement code. This Brackey's video is one of the best in my opinion:



    Good luck mate!