Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Raspilicious · Feb 21, 2013 at 12:29 PM · tilerangedrawdrawlinehex

How to draw an outline around multiple hexagon game objects?

Hey again everybody :)

My question is, how would I go about creating an outline around multiple hex tiles such as in the picture below? And on that note, around hex tiles in oddly shaped patterns, such as if an object was in the way of multiple tiles? Note: think the new XCom game, the way they show the movement ranges of the units... but in hexagon format.

alt text

The backstory of the project I'm working on is that it is a hex-based strategy game, and the movement and attack ranges of the units would be shown on the hex tiles.

I'm stuck as to how to solve this problem though. I've had multiple ideas of how to do it, ranging from using a projector and hex outline shape (wouldn't be valid at some times, as the move range could be blocked & reduced by a wall), using the GL class in unity, and even line renderers.

The GL class and line renderers seem like they could do the trick, but with either of them, I am unable to find the vector3 points of the outlines of the hexagon tiles. Well, I can find them using:

 Mesh mesh = GetComponent<MeshFilter>().mesh;
 Vector3[] vertices = mesh.vertices;

...but the vertices it provides me with are vertices around the game object (hexagonal prism as it were) as if the game object was sitting at 0,0,0 world coords, which it is not.

Does anybody have any suggestions of how to solve this, or even suggestions of an alternate way to do it?

attack range example idea.jpg (372.1 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gotys · Jan 15, 2014 at 08:59 AM 0
Share

This is a very good question, I am also interested in this. If someone has ideas, please let us know !

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by MarkFinn · Feb 21, 2013 at 02:15 PM

If it were mine, I'd highlight the affected/affectable tiles, rather than the outline. Much more generic and flexible approach I reckon. It'd allow you have indents in the area, or allow for line of sight and the like much more easily, rather than trying to calculate the outline shape.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raspilicious · Feb 21, 2013 at 02:25 PM 0
Share

That is the way it's being done now, but the issue with that comes when there are ramps. On the ramp, half the horizontally flat tile is inside the ramp, half is outside, like a spike sticking out of the ramp.

I've been working on some line calculations etc, and figured I can do something like this:

 void Start () {
     hexCenter = target.transform.localPosition;
     corners[0] = new Vector3(hexCenter.x+0.43f, hexCenter.y+1, hexCenter.z+0.25f);
     corners[1] = new Vector3(hexCenter.x, hexCenter.y+1, hexCenter.z+0.49f);
     corners[2] = new Vector3(hexCenter.x-0.43f, hexCenter.y+1, hexCenter.z+0.25f);
     corners[3] = new Vector3(hexCenter.x-0.43f, hexCenter.y, hexCenter.z-0.25f);
     corners[4] = new Vector3(hexCenter.x, hexCenter.y+1, hexCenter.z-0.49f);
     corners[5] = new Vector3(hexCenter.x+0.43f, hexCenter.y+1, hexCenter.z-0.25f);
     corners[6] = new Vector3(hexCenter.x+0.43f, hexCenter.y+1, hexCenter.z+0.25f);
     int i = 0;
     while(i < 6) {
         Debug.DrawLine(corners[i], corners[i+1], Color.green, 10);
         i++;
     }
 }

Then using a comparison between each hex tile I can find out ones that have really similar vertice and remove them from the list. Then the ones that remain I'd raycast down from each point to the terrain, and use a line renderer between the points and it should outline the hexes. What do you think?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

turret having a range of tiles 0 Answers

Drawing a Range Icon in 3D Space 0 Answers

Hexagonal grid with 120 degree angles 1 Answer

How can I highlight tiles that are in Range of attack? 1 Answer

Handles.DrawLine refresh rate in scene view 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges