I am making a platformer and I was trying to make a flip script myself which looks like this:
if (horizontal > 0)
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);
} else if (horizontal < 0)
{
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
}
But when I pressed the left arrow the player started flipping very fast from right to left. I still don’t know why. But I searched for another script and I found this:
Vector3 characterScale = transform.localScale;
if (horizontal < 0)
{
characterScale.x = -1;
}
if (horizontal > 0)
{
characterScale.x = 1;
}
transform.localScale = characterScale;
This script works fine. What is the difference between those scripts, why does my version goes crazy and the second one works fine?