- Home /
Bumpy WorldToScreenPoint
Hi guys,
I am trying to display a character name (to begin with) above the player (third person). I use WorldToScreenPoint(transform.position) in onGUI...
The player is walking with a navmesh agent on a navmesh baked terrain (point & click).
The name is following the player as desired but the name shakes a lot when I walk the player.
Any fix for this?
Thx
If the following object is bumpy but the character is not, and if the text is following the character using a script rather than parent child, then try moving the following code into LateUpdate().
There is no following object... Just an ongui on the player drawing a text string.
I have to agree with @robertbu here , throw all your camera and object following scripts into LateUpdate(). I notice below robertbu`s suggestion, you stated there is no following object but the scenario you are describing in your question denotes the very characteristic features you say are not there.
Could, for clarity, you please post your code so we may actually be able to view it and quicker identify your issue. we would need to see any code attached to your gui object, any relevant code attached to your player object, and if you can, a quick screenshot of your Hierarchy panel in the Unity ID$$anonymous$$
Thanks bud, sorry its not a resolve as of yet, but if you post what I mentioned above, we may be able to assist you an awful lot quicker than taking mere stabs(though i`m pretty sure whats been suggested will most likely turn out to be your issue), if you get me.
Take care bud Gruffy
Answer by Royall · May 04, 2014 at 01:18 PM
Ok, I figured it out myself... I needed to ceil the screenpoint values with Mathf.CeilToInt
Here is the code:
function OnGUI() {
var namePlatePos : Vector3 = Camera.main.WorldToScreenPoint(transform.position);
GUI.Label(Rect(Mathf.CeilToInt(namePlatePos.x), (Screen.height - Mathf.CeilToInt(namePlatePos.y)), 100, 50), username);
}
@Royall - I'm glad you solved your problem. Based on your 'solution' I hope you realize that without your code, there is no way we could have answered your question. And your question as asked does not point to this as solution. $$anonymous$$ore complete information would help us help you with future questions.
Your answer
Follow this Question
Related Questions
How to queue NavMeshAgents on entering a tile in Unity (based on path distance to tile)? 0 Answers
NavMeshAgent collision not working with player 2 Answers
NavMesh Agent rotation problem 3 Answers
WayPoints navMeshAgents help 0 Answers
enable/disable navmesh agent and obstacle same object (player) 0 Answers