What in this script is causing the sprites to face backwards rather than forwards?

I found the code snippet below and am using it to make the sprites in my fps game always look at the camera [player] position when I move around. But not only does it make the sprites turn to face the player’s position; it makes them do so facing backwards and therefore they become completely invisible in the game (unless I stick them to a parent object and flip it 180 degrees). This happens whether I use standard sprites, sprite renderers or animations on sprites, and I can’t figure out what it is in the code that’s making them face the player backwards rather than forwards.

using UnityEngine;
public class Billboard : MonoBehaviour
{
    Camera target;
    void Start()
    {
        target = Camera.main;
    }
    void Update()
    {
        Vector3 targetPosition = new Vector3(target.transform.position.x, transform.position.y, target.transform.position.z);
        transform.LookAt(targetPosition);
    }
}

Does anyone know why this issue is happening and how to solve the problem so the sprites always turn to face the player but do so facing forwards by default?

Hi @impurekind - So you are doing something like old school billboard sprites in the Doom and the like.

Unity manual says this about transform.LookAt; “Rotates the transform so the forward vector points at /target/'s current position.”

So if axis of sprite is forward is actually it’s z-axis, just take a look at it in 3d space and compare it to camera - you might have to just do what you suggested; rotate your sprite under parent) or alternatively, negate the target position (-target.transform.position).