- Home /
Move player canvas along with player parent.
I have a player canvas which represents the player name, and this is attached to a 3D sphere which is moving using AddForce. How can I keep the canvas to always be above the player, regardless of the rotation/position of the parent?
I can stop the canvas from rotating by using the answer from Here However, the canvas moves in a weird manner.
Answer by RealFolk · Jan 24, 2021 at 06:09 AM
Attach this script to the canvas that is parented to the player.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TextOverPlayer : MonoBehaviour
{
void Update()
{
transform.rotation = Quaternion.LookRotation(Camera.main.transform.forward);
}
}
Hi, this one works well as it fixes the rotation. However, the Canvas is a little offset upwards, so it still looks weird when the sphere moves.
For this particular problem I used the code From This Question , moved the Canvas to be at the center of the player and then just set the offset to be on the text itself.
I guess that in general nesting children like this could work in overco$$anonymous$$g this issue.
Also a good link to follow would be this tutorial.