Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by oliver-jones · Feb 01, 2017 at 03:23 PM · mathgridcoordinate-systemhexagon

Hexagon Grid

Hello,

I've built a hexagon grid using some coordinates that I input into the game. However, the algorithm I'm using to place these doesn't appear to be how I want it.

This is how it places them currently:

alt text

I would like the X axis to be horizontal, however it currently goes diagonal lower-right. This is how I would like it to be:

alt text

As you can see, the X axis is horizontal, with every odd on a negative placement (1,0.. 3,0.. 5,0.. etc).

This is the algorithm I'm using:

 public static Vector3 HexCoordinateToWorld(Vector2 _coordinates){
 
         float _sqrt32 = (float)Mathf.Sqrt(3)/2;
         float _size = 40.24f;
 
         float _x = _size * (float)_coordinates.x * 1.5f;
         float _y = _size * (2 * _coordinates.y - _coordinates.x) * _sqrt32;
 
         return new Vector3(_x, 0, _y);
     }


actual.png (42.7 kB)
a-wanting.png (42.0 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 _dns_ · Feb 01, 2017 at 03:42 PM 0
Share

Hi, there is a very interesting article about hex grids here: http://www.gamasutra.com/blogs/HermanTulleken/20140912/225495/20_Fun_Grid_Facts_Hex_Grids.php It contains a link to a document (h)exploring the subject: http://www.gamelogic.co.za/downloads/Hex$$anonymous$$ath2.pdf

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by ASPePeX · Feb 01, 2017 at 03:44 PM

Build it like it was a rectangular grid and then offset every odd row.

The Y calculation would be looking something like this:

 if (_coordinates.x % 2 == 0)
 {
    //don't offset Y position
 }
 else
 {
    //offset Y position
 }
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 FortisVenaliter · Feb 01, 2017 at 07:00 PM 1
Share

This is correct, but to expand on the concept, you ought to be able to boil it down to one line, like so:

 float _y = _size * (2 * _coordinates.y + ((_coordinates.x % 2 == 1) : 1 : 0)) * _sqrt32;

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

67 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Highlighting tiles on a hexagonal grid 1 Answer

Shader local space doesn't match object local space? 2 Answers

How can I calculate a list of points where a line intersects a grid? 1 Answer

How can customize which prefabs are instantiated in a grid? 1 Answer

How do I snap an object to a circular grid 2 Answers


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