Flip 2D object on X axis because of a moving target.

Hi, I found some nice scripts here, but not exactly what I want. The ones I found one uses: Input command. But I don’t want this because the object won’t be controlled by the player. I’m looking this :

When the target is now to the left of our object, the object flips in the opposite direction and vice versa!

I need :

public Transform target;

In my opinion transform.eulerAngles could be the solution. But I don’t how to build the script, I’m just a beginner and I’m not able to find the solutionsince the last two days.

I’m probably near of the goal with this :

if (x > 0) 
{

transform.Translate (x * Time.deltaTime, 0, 0);
transform.eulerAngles = new Vector2 (0, 0);

}

if (x < 0)

{

transform.Translate (-x * Time.deltaTime, 0, 0);
transform.eulerAngles = new Vector2 (0, 180);

}

I’m probably missing a big part or completely wrong.

Thank you very much!

What you are trying to do is fundamentally impossible.

You are trying to turn a sprite around and see it “from the other side”. But a sprite is a polygon with a texture mapped to it and a polygon only has one side.

What you need to do in order to create a sprite that is flipped horizontally is to reverse the texture by swapping the u,v coordinates.

My guess is however you don’t understand what U,V coordinates are.

The simplest solution for you probably thus is just to flip your art in a 2D art program and make two different sprites, one for each facing.