- Home /
Waypoint marker that counts distance from player
Hi, I am trying to do a script that shows how many meters away the waypoint is, just like in [this picture][1] [1]: http://image.gamespotcdn.net/gamespot/images/2009/features/gameguides/modern-warfare-2/032.jpg
On the image it indicates that the player is 18 meters away from the waypoint. The problem is that I don't know how to do this. Does anyone know how to do this or have a hint on how to do this?
Vector3.Distance(Players Position, Targets Position) This returns distance in unity units, which is the same as meters. If your objects are a different scale, you will have to adjust the given distance.
Ok, thanks. But how would I make this being displayed as a meter count under the waypoint?
Look into 3D text... you can then assign that text the output of Vector3.Distance as mentioned by Rabwin.
http://docs.unity3d.com/Documentation/Components/class-Text$$anonymous$$esh.html
http://docs.unity3d.com/Documentation/ScriptReference/Text$$anonymous$$esh-text.html
Using all the great info above, this is how I'd recommend putting it all together:
Create an empty child game object of the waypoint called DistanceLabel. This object will rotate to always face the camera (see step 3). If the waypoint object itself can rotate, then don't bother with the empty child object.
Add a Text $$anonymous$$esh component to it.
Add a script that keeps the label facing the camera -- for example:
public Transform player; void Update() { float distance = Vector3.Distance(player.position, this.position); GetComponent<Text$$anonymous$$esh>().text = string.Format("{0:N0}m", distance); transform.LookAt(Camera.main.transform); }
Your answer
Follow this Question
Related Questions
HELP- i can see shadows load in as i walk 1 Answer
Detect if player is in range? 0 Answers
A.I - what is better for player checking ? 0 Answers
Detect if player is in range? 2 Answers
Move player same distance every touch 2 Answers