Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question My player moves for my idle and walk animation

Discussion in 'Animation' started by TosoLeo, Mar 16, 2023.

  1. TosoLeo

    TosoLeo

    Joined:
    Dec 13, 2022
    Posts:
    5


    If someone knows howw to fix this, let me know Desktop Screenshot 2023.03.16 - 16.36.17.76.png Desktop Screenshot 2023.03.16 - 16.36.08.74.png
     
    Last edited: Mar 16, 2023
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I'm assuming you're switching between them in the animator?

    Find out why they're switching and then fix that.

    If you still need help, you need to give more information.
     
  3. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Too many possible causes here, Need more info.
     
  4. TosoLeo

    TosoLeo

    Joined:
    Dec 13, 2022
    Posts:
    5
    if someone
    I think that this thing is caused becasue the idle animation is from mixamo and the right foot is lower that the the left one, so, when i apply force when i switch from one animation to another, this happens
     
  5. TosoLeo

    TosoLeo

    Joined:
    Dec 13, 2022
    Posts:
    5
    I posted some animator photos and the inspector of the player, let me know if you need something more
     
  6. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    How are you switching between the animator states? What are your conditions? What is the code you're using for this? What does the animator look like when the game is running and the issue is occurring?
     
  7. TosoLeo

    TosoLeo

    Joined:
    Dec 13, 2022
    Posts:
    5
    i am switching animator states with the script assigned to the playe object called " Animation State Controll" and this is the script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class animationStateController : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     Animator animator;
    9.  
    10.     void Start()
    11.     {
    12.         animator = GetComponent<Animator>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.      
    19.      
    20.         controlWalking();
    21.         controlRunning();
    22.      
    23.     }
    24.  
    25.     private void controlWalking() {
    26.         bool walkPress = Input.GetKey(KeyCode.W);
    27.      
    28.          if(walkPress) {
    29.             animator.SetBool("isWalking", true);
    30.         } else if(!Input.GetKeyDown(KeyCode.W)) {
    31.             animator.SetBool("isWalking", false);
    32.         }
    33.     }
    34.     private void controlRunning() {
    35.         bool runPress = Input.GetKey(KeyCode.LeftShift);
    36.         bool walkPress = Input.GetKey(KeyCode.W);
    37.          if(runPress &&  walkPress) {
    38.             animator.SetBool("isRunning", true);
    39.         } else if(!runPress || !walkPress) {
    40.             animator.SetBool("isRunning", false);
    41.         }
    42.     }
    43. }
    i am switching the animator states with the bool parameters "isWalking" and "isRunning"

    The animator works normally as it should be but the problem still occurs
     
  8. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I don't see any issues with the code. Did you actually set any conditions in the animator transitions? Are the states switching because you have exit time enabled? If we could see the actually conditions that are firing incorrectly, that would be helpful.
     
  9. TosoLeo

    TosoLeo

    Joined:
    Dec 13, 2022
    Posts:
    5
    The same is for the running transitions but with the isRunning condition

     

    Attached Files:

  10. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Okay, I've completely misunderstood the issue. I read the title as "My player moves FROM my idle and walk animation" instead of "for."

    So, the issue is that your player is moving when you play those animations?

    The walk animation seems to have built in root movement. Pretty sure it's made to use root motion, not sure if there's an easy way to fix that aside from just using root motion:
    Root Motion.JPG

    Your character is falling over; this is likely because of your Rigidbody settings. To fix this, you could try freezing x and z rotation:
    Rigidbody.JPG
     
    Last edited: Mar 16, 2023