How to Get World Space Text to Look at The Player

So what I would like to do is to get my world space text to ALWAYS face the player, therefore they can read the text no matter what angle they walk up to the text from.

However the problem I am having is that the text is being portrayed as it would in a mirror, thus what I would like to do is rotate it 180 degrees whilst also looking at the player.

Here is the script I have at the moment:

    public Transform target;

    void Update()
    {
        if(target != null)
        {
            transform.LookAt (target);
        }
    }

So at the moment the text is perfectly looking at the target, but how would I also rotate the text on the y axis?

My quick attempt was this, but at no avail:

transform.LookAt (target.localPosition, target.localRotation.y + 180, target.localScale);

Any help is appreciated! :slight_smile:

LookAt changes the rotation so the object’s looking at the point the player’s standing in world space. Your quick attempt is using a mix of the player’s local position and the y-component of the player’s rotation to look at something that’s nonsense, and almost certainly 180 meters above anything interesting.

There’s two good solutions here:

  • Look at the player, and then rotate 180 degrees:
transform.LookAt(target);
transform.rotation *= Quaternion.Euler(0, 180, 0);

Update happens before things are drawn to the screen, so the 180-degree back and forth won’t be visible.

  • Fix this in the text gameObject:
    Use the code as you have it now, but put the text as a child object, rotated 180 degrees relative to the parent.
1 Like
 public Transform target;

    void Update()
    {
        if (target != null)
        {
            transform.LookAt(transform.position-target.position);
        }
    }

(fixed it)

1 Like

Thank you very much guys, both of your solutions worked :slight_smile:

Hopefully I can solve something simple like this myself next time :slight_smile:

P.S. Damn Quaternions…

@LeftyRighty , that’s a bit too clever. “Look at something at the exact opposite side of me as the player”?

I like it.

1 Like