2D (look at) object disappears

I have a moving object that I want to look at the target it’s moving towards, here is my code:

 void Update()
     transform.LookAt( target.transform.position);

The problem is the object does look at the target while moving, but since the game is in 2D view, the object kinda turns sideways, what is happening is that it turns and faces the object it’s looking at.

Not sure, but it sound like you need to specify the LookAt function with the “up” direction. If you are using a 2D space this will be the coordinate you are NOT using. So if you are using x, and z for the 2D space, specify the lookAt “up” parameter using new Vector3(0,1,0) (if using x and y for your 2D space, then specify (0,0,1) for “up”)

Note: by default, if you DON’T provide the “up” direction, it will use Vector3.up=(0,1,0) [so, if you ARE using X and Z in your 2D space, this answer is NOT the solution.]

Some more detail about using the LookAt Function: This is a function that can take one OR two parameters. If you only give it one; it will automatically pass a “default” value (for LookAt, the default value is Vector3.up).

Since the lookat function deals with 3D vectors, you may need to specify the second parameter yourself.

When you “look at” something, in the real world, and tilt your head, you are changing the second parameter for the LookAt Function.

If you use the wrong value for this “head tilt”, in your 2D world, it might turn your object “into” the screen (and from the edge a 2D object is not visible since it has no thickness.)