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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

My model doens't stop moving with transform.translate

Discussion in 'Scripting' started by foxvalleysoccer, Apr 10, 2017.

  1. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    If I don't bump the model (not the player) walking around the scene the script works fine.
    But if I bump the model with my character controller the model will continue to move once it hits the waiting animation state.

    Why would that happen? How can i fix it?

    Code (CSharp):
    1. public class MoveMan2 : MonoBehaviour
    2. {
    3.  
    4.     public float speed = 0.85f;
    5.     public Animator anim;
    6.     void Start()
    7.     {
    8.         anim = GetComponent<Animator>();
    9.         InvokeRepeating("SetWalkMode",5.0f,20.0f);
    10.     }
    11.      
    12.     void SetWalkMode()
    13.     {
    14.         anim.Play("SkitsWalk", -1, 0f);
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if (anim.GetCurrentAnimatorStateInfo(0).IsName("SkitsWalk"))
    20.         {
    21.             Debug.Log("Skits walking");
    22.             transform.Translate(0, 0, speed * Time.deltaTime);
    23.         }
    24.         if (anim.GetCurrentAnimatorStateInfo(0).IsName("Wait"))
    25.         {
    26.             Debug.Log("Waiting");
    27.         }
    28.     }
    29. }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    I suspect this is more an issue with your animator controller than the script. Are you sure that the animator controller is transitioning away from the SkiteWalk animation when that animation finishes?
     
  3. foxvalleysoccer

    foxvalleysoccer

    Joined:
    May 11, 2015
    Posts:
    108
    I removed the rigidbody and things work correctly now.