- Home /
Question by
AlexReverse · Jul 12, 2018 at 05:34 PM ·
c#animatoranimations
When the player turns around the idle animation plays for one frame.
So i have this problem with the animations. The idle animation plays when the player turns around (while running). This is how it looks: youtube video
And this is the "player" script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float maxspeed = 3;
public float speed = 50f;
public float jumppower = 150f;
float size = 0.2f;
public bool grounded;
private Rigidbody2D rb2d;
private Animator anim;
void Start () {
//player movement
rb2d = gameObject.GetComponent<Rigidbody2D>();
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
anim.SetBool("Grounded", grounded);
anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis("Horizontal")));
if (Input.GetAxis("Horizontal") < -0.1f)
{
transform.localScale = new Vector3(-size , size , size);
}
if (Input.GetAxis("Horizontal") > 0.1f)
{
transform.localScale = new Vector3(size, size, size);
}
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
//limiting the speed
rb2d.velocity = new Vector2(h * maxspeed, rb2d.velocity.y);
rb2d.AddForce((Vector2.right * speed) * h);
if (rb2d.velocity.x < -maxspeed)
{
rb2d.velocity = new Vector2(-maxspeed, rb2d.velocity.y);
}
}
}
Comment
Do you have the "Has exit time" check box unselected in the transition between Idle and Runing?
Show more comments
Answer by Arctous · Jul 12, 2018 at 08:00 PM
What are the parameters and states on your animation controller?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Animations out of sync? 0 Answers
how i can stop the animator to play trigger animation? 1 Answer