Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Running animation loop is weird (see video) (c#)

Whenever my character runs, it has this weird loop, I asked other people and I checked tutorials. I could not find it. See video for more information.

Video:

Video

Code:

public GameObject thePlayer;
public bool isRunning;
public float horizontalMove;
public float verticalMove;

void Update () {
    if (Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
    {
        thePlayer.GetComponent<Animation>().Play("Run");
        horizontalMove = Input.GetAxis("Horizontal") * Time.deltaTime * 150;
        verticalMove = Input.GetAxis("Vertical") * Time.deltaTime * 8;
        isRunning = true;
        transform.Rotate(0, horizontalMove, 0);
        transform.Translate(0, 0, verticalMove);
    }
    else
    {
        thePlayer.GetComponent<Animation>().Play("Idle");
        isRunning = false;
    }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The reason for that could be that you get the component each frame instead of just getting it once. That could cause problems. Try doing this:

void Start()
{
     anim = thePlayer.GetComponent<Animator>();
}

and then play it in the Update function like this:

anim.Play("Run");

and then in your else statement, do the same with Idle just to make sure:

anim.Play("Idle");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!