- Home /
Question by
kinggamer1235 · Jan 26, 2015 at 09:12 PM ·
2d-platformerflip
2D character not flipping?
I am following the character controllers tutorial by unity, I cant seem to get this to work. I have checked 3 times now and I cant find out what's wrong.
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
if(move > 0 && !facingRight)
{
Flip ();
}
else if(move < 0 && facingRight)
{
Flip ();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= 1;
transform.localScale = theScale;
}
}
The camera is not attached to the character btw. Thanks for any help I get!
Comment
Best Answer
Answer by Chris333 · Jan 26, 2015 at 09:37 PM
Hi,
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1; //you need to multiplicate it with -1 not 1 to flip the coords
transform.localScale = theScale;
}
You forgot the minus in your Flip method.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181611im_/https://answers.unity.com/themes/thub/images/avi.jpg)