Flipping object when moving to left or right

36 views Asked by At

Dumb question but I'm new to it So I'm trying to make a 2d game where the player is a 2d object in the bottom of the screen collecting stuff that fall, I'm trying to make the player to look at the direction that it's moving

I tried this but it's not what I wanted

    void Update()
    {
        if(Input.GetMouseButton(0)) 
        {
            Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            if(touchPos.x < 0) 
            {
                rb.AddForce( Vector2.left * moveSpeed );
                transform.Rotate(new Vector4(0, 180, 0));
            }
            else
            {
                rb.AddForce(Vector2.right * moveSpeed );
                transform.Rotate(new Vector4(0, 180, 0));

            }

        }
        else
        {
            rb.velocity = Vector2.zero;
        }
    }
}
0

There are 0 answers