- Home /
Location/Area Display
I am making a small driving game for my friends just for fun. There are a few streets in my map which the player can drive the car around. I am trying to find a way to display the street name that the player is currently driving on.(Like in GTA IV/GTA V). And I also need to display the main region. What can I do to let the game detect which street/area the player is in?
Answer by einWikinger · Feb 15, 2015 at 07:58 AM
Some ideas:
Define trigger boxes for every area which belongs to a certain street and change the current street name when the player enters any of these boxes
Lay out lines in the middle of the streets and check which line is nearest to the players position and use that line as the current street
Use AABBs and then basically the same as with the lines (which box is nearest to the player, use that box as the current street). Has the advantage that you can model the volume of actual streets better than with lines
I hope this inspires you for a more specifically suited solution, if you got questions to any of these proposals just ask! The AABB / Line approach probably will involve some editor scripting, gizmo drawing at least.
Thank you very much for your advice. How can I check which line is the closest to the player's position?
A simple solution is to project the test point P onto the line AB and then calculating the distance of the projected point and P. Look into the method "ProjectPointOnLineSegment" on http://wiki.unity3d.com/index.php/3d_$$anonymous$$ath_functions
There are solutions which are less complex but I couldn't find one, but a bit of research lets you find a lot of samples for "distance of point to line segment"!
Your answer
Follow this Question
Related Questions
How to display EULA from Doc in Unity? 0 Answers
Change the game window built 1 Answer
How to display text using javascript ? 1 Answer
Problem Displaying Score on GUI text 0 Answers
Location of Gameplay Window Relative to the Entire Screen 1 Answer