- Notifications
You must be signed in to change notification settings - Fork5
HexEngine is a library for working with hex coordinates for Unity.
License
MIT, Unknown licenses found
Licenses found
MIT
LICENSEUnknown
LICENSE.metaNotificationsYou must be signed in to change notification settings
juna8001/HexEngine
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
HexEngine is a library for working with hex coordinates for Unity.
Using cube coordinates, position of each hex can be represented using three values corresponding to the three primary axes (X, Y, Z).
HexEngine only stores the X and Y values.That's because on cube grid:
X + Y + Z = 0
so we can calculate the Z value when needed:
Z = - X - Y
If you want to learn more about cube coordinates, visitthis amazing guide.
HexCoordshexA=newHexCoords(-1,5);HexCoordshexB=newHexCoords(2,3);// add/subtract coordinatesHexCoordscoords=hexA+hexB;coords=hexA-hexB;// multiply by integercoords=hexA*2;coords=2*hexB;// move in given directioncoords=hexA+HexDirection.NE;// north-east direction from hexAcoords=hexB+HexDirection.S;// south direction from hexBcoords=hexA-HexDirection.NW;// negative north-west direction from hexA// get hex distance from coords (0, 0)intintValue=hexA.Magnitude();// get hex distance between two coordinatesintValue=hexA.DistanceTo(hexB);// get position of the center of a hex (value of y is always 0)Vector3vector=hexA.Offset();// iterate all neighbour coordinatesforeach(HexCoordsneighbourinhexA.Neighbours()){// do something with neighbour here}
HexDirectiondirection=HexDirection.NE;// get coordinates from directiondirection.Coords();// get Vector3 direction from hex directionvector=direction.Direction();// get angle of direction (0 for north direction, rising clockwise)direction.Angle();// rotating directiondirection=direction.Left();// rotate counterclockwisedirection=direction.Right();// rotate clockwisedirection=direction.Rotate(4);// rotate 4 times clockwisedirection=direction.Rotate(-2);// rotate 2 times counterclockwisedirection=direction.Opposite();// get opposite direction// get corner positions for hex edge in given directionvector=direction.LeftCorner();vector=direction.RightCorner();// get corner direction (similar to above, but normalized)vector=direction.LeftCornerDirection();vector=direction.RightCornerDirection();// iterate all directions clockwise starting from given directionforeach(HexDirectioniteratedDirectionindirection.Loop()){// do something here}
// convert from 3D point to HexCoordscoords=HexMath.PointToHexCoords(vector);coords=HexMath.PointToHexCoords(vector,gridScale:2f);// gridScale is optional parameter defining scale of hex grid// convert from 3D point to HexPosition// HexPosition is similar to HexCoords, but stores coordinates as float valuesHexPositionhexPosition=HexMath.PointToHexPosition(vector);hexPosition=HexMath.PointToHexPosition(vector,gridScale:2.5f);// convert HexPosition to HexCoords by rounding the coordinatescoords=HexMath.RoundPositionToCoords(hexPosition);}
About
HexEngine is a library for working with hex coordinates for Unity.
Topics
Resources
License
MIT, Unknown licenses found
Licenses found
MIT
LICENSEUnknown
LICENSE.metaUh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.