Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

HexEngine is a library for working with hex coordinates for Unity.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
NotificationsYou must be signed in to change notification settings

juna8001/HexEngine

Repository files navigation

HexEngine is a library for working with hex coordinates for Unity.

Coordinates

Using cube coordinates, position of each hex can be represented using three values corresponding to the three primary axes (X, Y, Z).coords boardHexEngine 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.

Basic Operations

HexCoords

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}

HexDirection

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}

HexMath

// 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
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp