All Projects → owenmoore → cube-coordinates

owenmoore / cube-coordinates

Licence: MIT License
Unity package providing a cube coordinate system for building and using hexagonal tiles for gameplay.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to cube-coordinates

2D-Platformer-Hunter
A 2D Platformer Controller in Unity
Stars: ✭ 153 (+565.22%)
Mutual labels:  unity-package
com.newblood.lightdata
Provides access to internal lighting APIs.
Stars: ✭ 49 (+113.04%)
Mutual labels:  unity-package
EvenVizion
Camera localization and video stabilization component. Fixed coordinates system. Using Python and OpenCV.
Stars: ✭ 38 (+65.22%)
Mutual labels:  coordinate-systems
ProceduralHexTerrainGenerator
Procedural Hex Terrain Generator
Stars: ✭ 20 (-13.04%)
Mutual labels:  hexagonal-grids
blender-importer-unity
A tool to fix orientation issues from Blender to Unity
Stars: ✭ 23 (+0%)
Mutual labels:  coordinate-systems
erkir
Երկիր (Erkir) - a C++ library for geodesic and trigonometric calculations
Stars: ✭ 26 (+13.04%)
Mutual labels:  coordinate-systems
HexGrid
WPF HexGrid Panel
Stars: ✭ 35 (+52.17%)
Mutual labels:  hexagonal-grids
GizmosPlus
A Unity Package that provides additional GIzmo shapes and tools.
Stars: ✭ 35 (+52.17%)
Mutual labels:  unity-package
colibri-vr-unity-package
This is the Unity package for COLIBRI VR, the Core Open Lab on Image-Based Rendering Innovation for Virtual Reality.
Stars: ✭ 41 (+78.26%)
Mutual labels:  unity-package
Lattice2
FreeCAD workbench about arrays of all sorts and kinds, and local coordinate systems
Stars: ✭ 40 (+73.91%)
Mutual labels:  coordinate-systems
hexagdly
Process hexagonally sampled data with PyTorch
Stars: ✭ 65 (+182.61%)
Mutual labels:  hexagonal-grids
coord
Toolkit for apply point transformations for vector.
Stars: ✭ 37 (+60.87%)
Mutual labels:  coordinate-systems
UnityHexagonLibrary2d
A library to manage 2D hexagonal tiles in Unity.
Stars: ✭ 58 (+152.17%)
Mutual labels:  hexagonal-grids

CubeCoordinates

Unity package providing a cube coordinate system and methods for building hexagonal tile grids for interactive gameplay.

Build a grid of cube coordinates A* Path Tracing Expand to connected coordinates

Install

To install, copy the CubeCoordinates Unity Package directory into your project's Packages directory.

using CubeCoordinates;

...

Coordinates coordinates = Coordinates.Instance;
coordinates.SetCoordinateType(Coordinate.Type.GenerateMesh);

List<Vector3> cubes = Cubes.GetNeighbors(Vector3.zero, 10);
coordinates.CreateCoordinates(cubes);

coordinates.Build();

Please check the examples folder and documentation zip to learn more.


How to Use

Coordinates

Used to create and manage Coordinate instances, it uses an "all" default Container as the master list for it's methods.

Coordinates coordinates = Coordinates.Instance;
coordinates.SetCoordinateType(Coordinate.Type.Prefab, myGameObject);

coordinates.CreateCoordinates(
    Cubes.GetNeighbors(Vector3.zero, 10)
);

Coordinate origin = coordinates.GetContainer().GetCoordinate(Vector3.zero);
Coordinate destination = coordinates.GetContainer().GetCoordinate(new Vector3(4,1,-5));

Coordinates.Instance.Build();

List<Coordinate> diff = coordinates.BooleanDifference(
    coordinates.GetNeighbors(origin, 4),
    coordinates.GetNeighbors(origin, 2)
);

List<Coordinate> path = Coordinates.Instance.GetPath(origin, destination);

Coordinate

Individual Coordinate instances represents tiles on the grid. It's purpose is to keep track of cube coordinates, transform position in world space, reference any GameObject instantiated to represent it, facilitate path finding by storing cost values and be supplied as an origin for many Coordinate operations.

Coordinate coordinate = Coordinates.Instance.GetContainer().GetCoordinate(new Vector3(4,1,-5));
myGameObject.transform.position = coordinate.position;
coordinate.SetGameObject(myGameObject);

Container

Any number of Container instances can be optionally created - except for "all", which Coordinates uses as a master list internally - to manage your own lists of Coordinate instances that you can later retrieve for your own purposes.

Container moveArea = Coordinates.Instance.GetContainer("move_area");
moveArea.AddCoordinates( new List<Coordinate>{coordinateA, coordinateB});

foreach(Coordinate c in moveArea.GetAllCoordinates())
    c.go.GetComponent<MyScript>().DoSomething();

movement_range.RemoveAllCoordinates();

Cubes

Collection of cube coordinate system methods for calculating desired coordinate results. These methods do not map to Coordinate instances; they simply calculate results from an infinite plane of coordinates as requested. Using Cubes directly is desirable when combining several operations together because you can calculate the results and last pull any matching Coordinate instances from a Container by supplying the results.

List<Vector3> attackShape = Cubes.BooleanCombine(
    Cubes.GetRing(Vector3.zero, 4),
    Cubes.GetDiagonalNeighbors(Vector3.zero, 3)
);

Vector3 activeCube = Cubes.ConvertWorldPositionToCube(myGameObject.transform.position);

List<Vector3> attackShapeOnMap = new List<Vector3>();
foreach (Vector3 cube in attackShape)
    attackShapeOnMap.Add(cube + activeCube);

Container attackTiles = Coordinates.Instance.GetContainer("attack_tiles");
List<Coordinate> attackShapeCoordinates = attackTiles.GetCoordinates(attackShapeOnMap);

foreach (Coordinate c in attackShapeCoordinates)
    c.go.GetComponent<MyScript>().DoSomething();

MeshCreator

Used to generate hexagonal meshes when using Coordinate.Type.GenerateMesh which is useful for debugging.


Credit

This package was developed by largely following the explanations found on this post:

https://www.redblobgames.com/grids/hexagons/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].