I need help with some grid calculation for a digital board game.

So first of all I should show you an image of the board so you have a visual.

So this is how the board will look like and the White Dot in the bottom is a capsule which is currently representing the player. The basic movement is like this. You throw a dice, you get a random number between 1 and 6. If you get for example 4, the tiles that are 4 tiles away from the one your currently standing on will light up and become clickable. This is all working just fine and without problems.

What I do need a little help with is making only the tiles that are clockwise light up. So the player can only move clockwise on the board. I started programming this by checking the X- and Z-axis of the tile and comparing them with the current position of the player and check if the tile is clockwise or not. This is working for 90% but isn’t really optimized or very good for performance.

So somebody told me I should do it like this.

Calculate the angle between the position of the player and the position of the tile with polar coordinates and if it’s higher then it is clockwise otherwise it’s not. I gave this a shot, but the coordinates that are returned seem like they are not on a grid from 0 degrees - 360 degrees. So I was wondering if someone could help me on how I should calculate this, or if they have an even better idea on how to handle this?

I take it your tiles are part of a collection? And you can easily get a collection of tiles to check with something like

List<Tiles> clickable = GetAllTilesWithinStepsOf(int steps, Tile playerTile);

This way you’ve only got to run your IsClockwise() check on the tiles which actually matter.

I’m in a hurry and can’t test this, but I think this should get you very close. You may need to reverse which argument comes first (playerPosition or tilePosition).

The .z in the sign test might need to be .x or .y depending on the planar orientation you’ve chosen for your project.

Just pass in the tile’s position for a and the player’s position for b, and this should give you useful data. Note that a and b must share the same “height” in whatever planar orientation you’re using for this to be foolproof.

 bool IsClockwise( Vector3 a, Vector3 b ) {       
    return ( Vector3.Cross(a,b).y < 0 );
 }