I wish to create a hexagon type game where a player can only move in one direction at a time in the same direction (can not change).
Please see image attached.
I have created a small environment but unsure how to control/restrict my player’s movement. Could someone suggest a good starting point?
I realise the hexagon is made up of side equal sides and that the movement direction must intersect an edge or maybe between two points of an edge? Or I guess my players direction is fixed in degrees, like the player can only move in 60 degrees angles?
The way I would recommend doing this is to have a system to calculate each position on the hexagonal grid and then move the objects to the target position. This type of thing is long overdue for a code sample, so I’ve attached one to this post. There are some comments in the script that (hopefully) describe how it works, but add to the thread if you need further explanation or find any bugs, etc.
i’ve actually just emerged from completing a hexgrid system, and it functions similarly to what Andeeee is saying (I don’t have the opportunity to look at the code sample just now). Basically, I just pre-calculated the centers of each hexagon for the entire map, and each hexagon stores the id of its adjacent hexagons. If you were to assign numerical ids to each side of the hexagons, then you could just code something simple that checks the direction the player wants to move, find the adjacent hexagon that corresponds with that direction, and move the player to that position.
Why precalculate when you can calculate them at any time? Nowadays lack of memory isn’t going to stop the game, but I’m curious about other benefits that can have doing precalculation (and I’m unaware of).