Thank you! This is simple and straightforward. Only suggestion would be to move your face cam on the screen to somewhere where it doesn’t cover the inspector as much. Thanks again 🙏🏻
Thank you! and here's the script for everyone. Don't forget to manually assign the variables, i set them all as public. using UnityEngine; using UnityEngine.UI; public class UIFollow3DObject :MonoBehaviour { public Transform mainCam; public Transform target; public Transform worldSpaceCanvas; public Vector3 offset; private void Start () { mainCam = Camera.main.transform; transform.SetParent(worldSpaceCanvas); } void Update () { transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera transform.position = target.position + offset; } }
Thanks so much. The video is only 720 so this is way nicer than following along. Any change you could explain how to manually assign the variables? I'm super new at this.
@@TheosResearchDiary Hey Thoreau! To manually assign variables, you can click, hold and drag the corresponding objects from the scene window onto the script’s variables in the inspector window.
@@TheosResearchDiary For the camera variable, find the camera in your scene. Click, hold and drag the camera to the mainCam variable on the Floating Text script in the inspector. With the target, you can do the same action with a game object in the scene ( what are you using? ). The canvas variable can be assigned by finding the Canvas in the scene that uses the World Space render mode. Drag and drop that object onto the script in the inspector. Is this what you are looking for? Thank you for checking out the channel!
@@jonbednez Thanks so much Jon! and for the great video. I haven't implemented anything yet but be sure to post and link to your channel when my team does. (small class project)
hello, first of all I would like to thank you for the tutorial, it is very helpful. So I experienced a little problem, yesterday after I tried your tutorial it worked, then after I opened the project a problem occurred, namely the text didn't appear when playing and in the hierarchy the text seemed to disappear. So where do you think the problem is?
hello! does the text disappear during runtime only? the text should parent itself to the world space camera at runtime, so its visible. could it be font or font size? is the width of the text box too small? are you using a world space canvas?
Maybe put your webcam overlay on the left bottom corner, since a few times you performed mouse and data entry actions that were actually obscured by your webcam frame.
ah good catch! I recently got a green screen, I'm hoping that also helps for future vids. I'll keep an eye on the overlay. Thanks for the advice! Did you find the code useful?
I saw a guy in another tutorial making one world space canvas for each character in the game, and making it a child of that character's game object, and you are using one canvas for all name tags in the game. He doesn't need to calculate the text's position since it's the child of the character GO and moves with it automatically, but it's not a hassle to move the text manually as you do. Is there any difference in having a single canvas for all name tags or one canvas for each? What is the better approach? If there are hundreds of characters with name tags in a scene, would creating hundreds of small canvases affect performance?
good question. I would look at the profiler. my solution is an alternate solution. multiple canvases is probably best practice. I found some useful answers to your question ➤ community.gamedev.tv/t/multiple-canvases-is-recommended-by-unity/198288 and ➤ stackoverflow.com/questions/74699735/what-are-the-performance-implications-of-using-multiple-world-space-ui-canvases. have a great weekend! and thanks for checking out the content. cheers.
Isn't using texts or images without canvas more performance-friendly? And instead of LookRotation() method shouldn't we use text.forward = camera.forward? And instead of adjusting text's position by our hand, shouldn't we do it by code which calculates collider's bound size and would work for any size of object? Idk, these are my ideas
great ideas! are you referring to Sprites, 3d text, Raw Images? If you are experiencing performance issues, I would check the profiler. I’m not sure in terms of performance, probably depends on the amount of floating text you have rendering at one time. LookRotation is a preference. Yea, we could calculate collider bounds for y position. That’s why I love coding. Lots of various solutions. Thanks for watching.
@@jonbednez The reason I chose Unity over Unreal is its simplicity. I don't care much for Unreal's graphics, but Unity's simplicity comes at the cost of not having as good performance as Unreal. So, I always try my best to maximize my game's performance. I have no performance issues, as I get about 400 FPS, but I still want my game to be playable on weaker PCs as well. I'm using sprites for the health bar and TextMeshPro for the names, and in my game, where we look at objects from above, the camera never rotates (like in Kingsroad). So, I don't have to use the look-at-camera method for them. I'm also using object pooling for damage texts. Again, no performance issues, but still trying my best to have as good performance as possible
@@nikson12gg ok that makes sense. all good points. Object pooling is a great idea, especially if you have 1000s of objects. ok, I see why you asked about the world space canvas, you are using sprites instead. I think it really depends on how much UI you have displayed at one time. I use the overlay canvas for my UI buttons and world space for the floating text. I probably have about 20 health bars / floating text at one time. What kind of game are you making? I'm available if you ever need someone to test / playthrough, etc.
@@jonbednez thank you so much for your interest, but I'm developing my game very slowly and there is not much things to see yet. Do you know Kingsroad? That game was epic, bat sadly they shut down for some reason. I'm very into rpg games and Kingsroad was like it. Kingsroad wasn't open-world, we were just moving to new scenes(always teleporting instead of moving kilometers by foot like in open worlds). I would like creating a game like Kingsroad and I know my knowledge yes it very small for that, but step by step I learn things. I'm a new developer so I need time
@@nikson12gg No problem. I've never played Kingsroad. I was just looking it up, reminds me of Diablo. Back in the day, I used to play flash games on Newgrounds / Kongregate. Looks like it was a fun game. I'm reading it moved to mobile IOS/Android? Anyway, I'm always trying to learn new things too, still working on a game myself. Thanks for the feedback. Good luck!
Hi justpablo! In trying to help solve what's happening, I have some questions for you. :) 1. Are you modifying the floating text offset (It could be the Z Vector)? 2. Is the floating text under the World Space Canvas in the hierarchy? 3. If you look at the World Space Canvas, what is the Order in Layer number (the higher the number - the more priority)? 4. Are you using a Unity Standard Transparent Shader or is this a Custom Shader? 5. The transparent object -> Is this a gameobject in the scene? Thanks!
hey! in the beginning of the Update() function of the Floating Text script. you could add a check to see if the target exists. You can destroy the gameobject or use object pooling. void Update () { //check if target exists, if not, remove from scene if(target == null) { Destroy(this.gameObject); return; } transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera transform.position = target.position + offset; } If you want an alternative to destroying, you could try object pooling as an alternative. Here is the tutorial ➤ ua-cam.com/video/HnyaCNw6quM/v-deo.htmlsi=lTcHkmscGvQkU8JT Cheers.
@@jcarpio5410 Great question. TBH, I have never worked with Augmented Reality, so I can't speak to that. However, if you are using a World Space Canvas and a Camera in your scene, it would lead me to believe it would be possible. (but I haven't tested with AR). I found this tutorial -> ua-cam.com/video/HyQBv_1nhxQ/v-deo.html. It says using 3d world space UI with AR. I hope this helps! Thank you for your question. (If this works with AR, please let me know! I am very curious)
hey! is the world space canvas too large? has that canvas been adjusted to be in front of the camera? maybe the scale of the ui? could be font size is too large?
You're obscuring the Inspector with your weirdly skewed webcam. Do we really need to see you? Can't see what you're clicking on in there. If we really must see your face, could you put it on the other side of the screen where you're not obscuring important info?
hey! sorry about that. In the future I will def be mindful of the webcam. That’s a good idea about moving to the left of the screen. No, my face doesn’t have to show. I’m trying to learn what works and doesn’t with video. Thanks for the feedback.
Do you use floating text in your game? What kind of font looks best? Is there a color or effect that helps them stand out more?
Thank you so much for the tutorial!!!! People like you who make tutorials like this are absolute heroes!!!!
Thanks for watching! I'm glad you found this helpful.
Thank you! This is simple and straightforward. Only suggestion would be to move your face cam on the screen to somewhere where it doesn’t cover the inspector as much. Thanks again 🙏🏻
thanks for the tip! im always looking to grow and adapt. this is helpful. glad u found this tutorial useful
Thank you! and here's the script for everyone. Don't forget to manually assign the variables, i set them all as public.
using UnityEngine;
using UnityEngine.UI;
public class UIFollow3DObject :MonoBehaviour
{
public Transform mainCam;
public Transform target;
public Transform worldSpaceCanvas;
public Vector3 offset;
private void Start ()
{
mainCam = Camera.main.transform;
transform.SetParent(worldSpaceCanvas);
}
void Update ()
{
transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera
transform.position = target.position + offset;
}
}
Awesome! Are you implementing this or similar script into your game / app?
Thanks so much. The video is only 720 so this is way nicer than following along. Any change you could explain how to manually assign the variables? I'm super new at this.
@@TheosResearchDiary Hey Thoreau! To manually assign variables, you can click, hold and drag the corresponding objects from the scene window onto the script’s variables in the inspector window.
@@TheosResearchDiary For the camera variable, find the camera in your scene. Click, hold and drag the camera to the mainCam variable on the Floating Text script in the inspector. With the target, you can do the same action with a game object in the scene ( what are you using? ). The canvas variable can be assigned by finding the Canvas in the scene that uses the World Space render mode. Drag and drop that object onto the script in the inspector. Is this what you are looking for? Thank you for checking out the channel!
@@jonbednez Thanks so much Jon! and for the great video. I haven't implemented anything yet but be sure to post and link to your channel when my team does. (small class project)
That's what we need! Great tutorial!! Thank you so much! Keep it up! 😁👍
Thanks, will do!
hello, first of all I would like to thank you for the tutorial, it is very helpful. So I experienced a little problem, yesterday after I tried your tutorial it worked, then after I opened the project a problem occurred, namely the text didn't appear when playing and in the hierarchy the text seemed to disappear. So where do you think the problem is?
hello! does the text disappear during runtime only? the text should parent itself to the world space camera at runtime, so its visible. could it be font or font size? is the width of the text box too small? are you using a world space canvas?
Thanks dude!
No problem! Glad u found this helpful.
Thank you. this video helped a lot. but one issue that u could easily fix is setting the font of cisual studio as a bigger. have a nice day:)
np. thank you for the helpful advice! I'll make those changes for future videos. glad you found this helpful. have a great day as well.
Maybe put your webcam overlay on the left bottom corner, since a few times you performed mouse and data entry actions that were actually obscured by your webcam frame.
ah good catch! I recently got a green screen, I'm hoping that also helps for future vids. I'll keep an eye on the overlay. Thanks for the advice! Did you find the code useful?
@@jonbednez Yeah was well put together, short and concise.
I saw a guy in another tutorial making one world space canvas for each character in the game, and making it a child of that character's game object, and you are using one canvas for all name tags in the game. He doesn't need to calculate the text's position since it's the child of the character GO and moves with it automatically, but it's not a hassle to move the text manually as you do. Is there any difference in having a single canvas for all name tags or one canvas for each? What is the better approach? If there are hundreds of characters with name tags in a scene, would creating hundreds of small canvases affect performance?
good question. I would look at the profiler. my solution is an alternate solution. multiple canvases is probably best practice. I found some useful answers to your question ➤ community.gamedev.tv/t/multiple-canvases-is-recommended-by-unity/198288 and ➤ stackoverflow.com/questions/74699735/what-are-the-performance-implications-of-using-multiple-world-space-ui-canvases. have a great weekend! and thanks for checking out the content. cheers.
Is there any difference in using "Text - Legacy" and "Text - TextMeshPro" for the name tag?
hey! tbh. I don't use much of TextMeshPro, so I can't speak to that.
Isn't using texts or images without canvas more performance-friendly? And instead of LookRotation() method shouldn't we use text.forward = camera.forward? And instead of adjusting text's position by our hand, shouldn't we do it by code which calculates collider's bound size and would work for any size of object? Idk, these are my ideas
great ideas! are you referring to Sprites, 3d text, Raw Images? If you are experiencing performance issues, I would check the profiler. I’m not sure in terms of performance, probably depends on the amount of floating text you have rendering at one time. LookRotation is a preference. Yea, we could calculate collider bounds for y position. That’s why I love coding. Lots of various solutions. Thanks for watching.
@@jonbednez The reason I chose Unity over Unreal is its simplicity. I don't care much for Unreal's graphics, but Unity's simplicity comes at the cost of not having as good performance as Unreal. So, I always try my best to maximize my game's performance. I have no performance issues, as I get about 400 FPS, but I still want my game to be playable on weaker PCs as well.
I'm using sprites for the health bar and TextMeshPro for the names, and in my game, where we look at objects from above, the camera never rotates (like in Kingsroad). So, I don't have to use the look-at-camera method for them.
I'm also using object pooling for damage texts. Again, no performance issues, but still trying my best to have as good performance as possible
@@nikson12gg ok that makes sense. all good points. Object pooling is a great idea, especially if you have 1000s of objects. ok, I see why you asked about the world space canvas, you are using sprites instead. I think it really depends on how much UI you have displayed at one time. I use the overlay canvas for my UI buttons and world space for the floating text. I probably have about 20 health bars / floating text at one time. What kind of game are you making? I'm available if you ever need someone to test / playthrough, etc.
@@jonbednez thank you so much for your interest, but I'm developing my game very slowly and there is not much things to see yet. Do you know Kingsroad? That game was epic, bat sadly they shut down for some reason. I'm very into rpg games and Kingsroad was like it. Kingsroad wasn't open-world, we were just moving to new scenes(always teleporting instead of moving kilometers by foot like in open worlds). I would like creating a game like Kingsroad and I know my knowledge yes it very small for that, but step by step I learn things. I'm a new developer so I need time
@@nikson12gg No problem. I've never played Kingsroad. I was just looking it up, reminds me of Diablo. Back in the day, I used to play flash games on Newgrounds / Kongregate. Looks like it was a fun game. I'm reading it moved to mobile IOS/Android? Anyway, I'm always trying to learn new things too, still working on a game myself. Thanks for the feedback. Good luck!
i have the problem that the text is behind my transparent object. Is there a way to fix this?
Hi justpablo! In trying to help solve what's happening, I have some questions for you. :) 1. Are you modifying the floating text offset (It could be the Z Vector)? 2. Is the floating text under the World Space Canvas in the hierarchy? 3. If you look at the World Space Canvas, what is the Order in Layer number (the higher the number - the more priority)? 4. Are you using a Unity Standard Transparent Shader or is this a Custom Shader? 5. The transparent object -> Is this a gameobject in the scene? Thanks!
how do i remove the text if the player object is destroyed?
hey! in the beginning of the Update() function of the Floating Text script. you could add a check to see if the target exists. You can destroy the gameobject or use object pooling.
void Update ()
{
//check if target exists, if not, remove from scene
if(target == null)
{
Destroy(this.gameObject);
return;
}
transform.rotation = Quaternion.LookRotation(transform.position - mainCam.transform.position); // look at camera
transform.position = target.position + offset;
}
If you want an alternative to destroying, you could try object pooling as an alternative. Here is the tutorial ➤ ua-cam.com/video/HnyaCNw6quM/v-deo.htmlsi=lTcHkmscGvQkU8JT
Cheers.
can I add more than one floating text?
yep! you could modify each components' offset to help with overlap. what are you looking to do?
Can this work on Augmented Reality? Because what I want to do is to augment the 3d object with floating text above it or all round it.
@@jcarpio5410 Great question. TBH, I have never worked with Augmented Reality, so I can't speak to that. However, if you are using a World Space Canvas and a Camera in your scene, it would lead me to believe it would be possible. (but I haven't tested with AR). I found this tutorial -> ua-cam.com/video/HyQBv_1nhxQ/v-deo.html. It says using 3d world space UI with AR. I hope this helps! Thank you for your question. (If this works with AR, please let me know! I am very curious)
@@jonbednez I really appreciate the reply and help. Thank you so much 🙌
@@jcarpio5410No problem! If you have any other Unity and/or game related questions please let me know. I hope your project goes well. Have a good one.
i have a problem where it won't show the text in game but in scene it does
hey! is the world space canvas too large? has that canvas been adjusted to be in front of the camera? maybe the scale of the ui? could be font size is too large?
You're obscuring the Inspector with your weirdly skewed webcam. Do we really need to see you? Can't see what you're clicking on in there. If we really must see your face, could you put it on the other side of the screen where you're not obscuring important info?
hey! sorry about that. In the future I will def be mindful of the webcam. That’s a good idea about moving to the left of the screen. No, my face doesn’t have to show. I’m trying to learn what works and doesn’t with video. Thanks for the feedback.
@@jonbednez alright then, I pardon you. Now iron your hands for repentance and you shall be absolved. Thanks for your tutorial.
@@johngrey5806lol. np.