Make usernames face camera at runtime

Hello! I have a text gameobject attached to the Player object. How do I turn the other players text objects towards my camera at runtime? (So their names are always readable).
Solution:
I have figured it out and I am honestly a tiny bit ashamed. It was simply executing the code from the wrong game object (game manager). I had the transform.LookAt code together with the code that fills in the username at runtime. The only thing I had to do is attach the transform.LookAt code to the display name object and that obviously fixed the issue.. Thanks again for the help! I will just hide under a rock for a while 😂 Have a great weekend!
Jump to solution
27 Replies
kapa.ai
kapa.ai9mo ago
Hi @Hippolicious || CardaStacks. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The provided knowledge sources do not contain specific information on how to make text objects attached to the Player object face the camera at runtime. However, you might find it helpful to review the Normcore Documentation (https://normcore.io/documentation/), which provides comprehensive information on various aspects of the NormalVR platform. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@366873530199179264> kapa.ai is still learning and improving, please let us know how it did by reacting below
Hippolicious || CardaStacks
@Normcore Assistant How do I sync the transform component of a gameobject?
kapa.ai
kapa.ai9mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To synchronize the transform component of a GameObject in NormalVR, you can use the RealtimeTransform component. Here are the steps: 1. Create an empty scene. Add a Realtime component to an empty game object and configure the appKey so it can connect. 2. Create a GameObject in the scene and add a RealtimeTransform component to it. 3. Export a build, and open it next to the editor. Hit Play in Unity. 4. Click the "Request Ownership" button on the RealtimeTransform inspector (not the RealtimeView inspector). 5. Drag the GameObject around in the scene and watch how it updates on the build automatically. The RealtimeTransform component has several properties that you can set to control what aspects of the transform are synchronized: - syncTransform: If true, the transform will sync its position, rotation, and scale with the model. - syncPosition: If true, the transform will sync its position with the model. - syncRotation: If true, the transform will sync its rotation with the model. - syncScale: If true, the transform will sync its scale with the model. - syncVelocity: If true, the rigidbody on this transform will sync its velocity with the model. - syncAngularVelocity: If true, the rigidbody on this transform will sync its angular velocity with the model. Remember, if you want to move an object, you need to request ownership of it. If you're not the owner, the datastore values are treated as the source of truth. For more information, check out the guide on RealtimeTransform (https://normcore.io/documentation/realtime/realtimetransform) and Synchronizing a GameObject (https://normcore.io/documentation/realtime#synchronizing-a-gameobject) in the Normcore Documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@366873530199179264> kapa.ai is still learning and improving, please let us know how it did by reacting below
Hippolicious || CardaStacks
That is a great answer! I will compare my code with the documentation.
maxweisel
maxweisel9mo ago
Fwiw, I don't think you want to use RealtimeTransform to sync the nametag rotation as it will be facing a different camera for each player. I don't think you'll want to use networking for that to be honest. @Normcore Assistant Without using Normcore, do you know how to use Unity to billboard a game object to face the camera?
kapa.ai
kapa.ai9mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- I'm sorry, but as an AI developed for NormalVR, I'm only able to provide information based on the provided knowledge sources, which are all related to the Normcore platform. I don't have the ability to provide information or instructions outside of these sources. For information on how to billboard a game object to face the camera in Unity without using Normcore, I recommend checking Unity's official documentation or community forums. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@353762082451095552> kapa.ai is still learning and improving, please let us know how it did by reacting below
maxweisel
maxweisel9mo ago
@Hippolicious || CardaStacks would be worth asking ChatGPT that question. I'm sure you'll get a solid answer. But in short, you want the nametag gameobject to billboard to face the active camera inside of LateUpdate(). That will ensure it looks correct for all players.
Hippolicious || CardaStacks
Ok thanks I will give it a try 😊🙏
Mechabit
Mechabit9mo ago
you can use lookat to make the name text face the camera https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
Hippolicious || CardaStacks
Yes that works for your own avatar but can't make it work for other players that is why I thought it was a multiplayer issue. Maybe I should reference the new initiated players's name objects differently...
Mechabit
Mechabit9mo ago
how I do it is put lookat script on my avatar prefab and then target mainCamera mainCamera being different on every local client you might be targeting the remote avatar which would make all the name tags point at themselves if you get me e.g. void LateUpdate(){ transform.LookAt(Camera.main.transform.position); }
Mechabit
Mechabit9mo ago
Camera.main is a built in gameobject tag in reality you'd want to cache this reference rather than calling it every frame as it searches through the whole scene
Hippolicious || CardaStacks
I do believe I am targeting the main camera. It is working for the player...just not for the new instantiated ones. I will re-check my code when I am back at my desktop.
Mechabit
Mechabit9mo ago
best post your script and show us what your avatar looks like
Solution
Hippolicious || CardaStacks
I have figured it out and I am honestly a tiny bit ashamed. It was simply executing the code from the wrong game object (game manager). I had the transform.LookAt code together with the code that fills in the username at runtime. The only thing I had to do is attach the transform.LookAt code to the display name object and that obviously fixed the issue.. Thanks again for the help! I will just hide under a rock for a while 😂 Have a great weekend!
Mechabit
Mechabit9mo ago
all good 👍
Towellie
Towellie9mo ago
You think it might be worth throwing some unity docs into kapas knowledge sources? Avoiding anything that references their own networking ?
maxweisel
maxweisel9mo ago
I wonder if Kapa is using the codellama models. if so, they should already have plenty of Unity knowledge. could be worth asking them about it
Towellie
Towellie9mo ago
I'll add a todo and follow up
maxweisel
maxweisel9mo ago
🙏🏻
Towellie
Towellie9mo ago
@Normcore Assistant Without using Normcore, do you know how to use Unity to billboard a game object to face the camera?
kapa.ai
kapa.ai9mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, in Unity, you can make a game object always face the camera (a technique often referred to as "billboarding") by rotating the object to face the camera in the Update method. Here's a simple example in C#:
void Update()
{
transform.LookAt(Camera.main.transform);
}
void Update()
{
transform.LookAt(Camera.main.transform);
}
In this code, transform refers to the Transform component of the game object the script is attached to, and Camera.main refers to the main camera in the scene. The LookAt function rotates the game object so its forward vector points at the camera's position. Please note that this is a basic example and might need to be adjusted based on your specific needs and setup. For more complex scenarios or for more information, you should refer to the Unity Documentation (https://docs.unity3d.com/ScriptReference/Transform.LookAt.html). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9mo ago
<@497453196797804544> kapa.ai is still learning and improving, please let us know how it did by reacting below