Using transform.localScale to flip object

I am using this line of code to flip the object around when it walks left or right (Im making a 2D game)

transform.localScale = Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z * -1);

The problem I am running into is that saying:

transform.Translate((Vector3.forward * moveSpeed)* Time.deltaTime);

always has the character moving to the right. This happens even if I flipped the object around. I thought that flipping the object would also flip its forward pointing direction. Am I doing something wrong?

1 Answer

1

No, as you've seen, the scale only affects the appearance. You would have to do something similar with the 'walk' code, the direction of movement vector.