- Home /
How to implement a flip direction to my 2D character controller?
I am new to C# programming and I have my character controller script here, but how can I make the sprite flip direction when controlling it? This is what I have so far.
public class CharacterController : MonoBehaviour {
public float speed = 1.0f;
public string axisHorizontal = "Horizontal";
public string axisVertical = "Vertical";
public Animator anim;
// Use this for initialization
void Start () {
anim = gameObject.GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis(axisHorizontal)));
anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis(axisVertical)));
transform.position += transform.right *Input.GetAxis(axisHorizontal)* speed * Time.deltaTime;
transform.position += transform.up *Input.GetAxis(axisVertical)* speed * Time.deltaTime;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613201351im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Flip 2D object on X axis because of a moving target. 1 Answer
how can I change a light with multiple triggers. ? 0 Answers
Flip 2D player in x-axis to face movement direction 5 Answers
I am having problems with making my character face the movement direction after stopping. 1 Answer
Unity - problem with arms rotation and flip, body flip and shotting - 2d shooter 1 Answer