When it comes to grid-based games, whether it’s a tabletop RPG or a video game, determining line of sight (LoS) is an essential part of gameplay. In this article, we will discuss how to find line of sight on a hex grid with coordinates. This is an important skill to master, as it will help you to quickly and accurately determine what a character can see from their current position. By the end of this article, you will have a solid understanding of how to find line of sight on a hex grid with coordinates.
What is Line of Sight?
Line of sight, or LoS, refers to the ability of a character to see a target or objective. In a grid-based game, this is typically determined by drawing a straight line from the character’s position to the target’s position. If the line passes through any obstacles, such as walls, trees, or other characters, then the character does not have line of sight to the target.
Why is Line of Sight Important?
Line of sight is important for a number of reasons. For one, it helps to determine whether a character can attack a target. If a character does not have line of sight to a target, then they cannot attack that target. Additionally, line of sight can be used to determine whether a character can be seen by an enemy. If a character is hiding behind an obstacle, then they may be able to avoid being seen by the enemy.
Finding Line of Sight on a Hex Grid
Finding line of sight on a hex grid is a bit more complex than on a square grid, but it’s still relatively straightforward. Here’s a step-by-step guide to finding line of sight on a hex grid:
- Convert the coordinates of the character and the target to the same grid system. For example, if the character is using a hex grid with coordinates (x, y), then the target should also be using the same grid system.
- Draw a line between the character’s position and the target’s position. This can be done by connecting the two sets of coordinates (x1, y1) and (x2, y2) with a straight line.
- Determine the slope of the line. On a hex grid, the slope of the line is given by the formula:
- Check the slope of the line against the hex grid. If the slope is less than 1, then the line passes through the bottom-left diagonal of each hex. If the slope is greater than 1, then the line passes through the top-right diagonal of each hex. If the slope is exactly 1, then the line passes through the top-left and bottom-right diagonals of each hex.
- Determine whether the line passes through any obstacles. If the line passes through an obstacle, then the character does not have line of sight to the target.
m = (y2 - y1) / (x2 - x1)
Example of Finding Line of Sight on a Hex Grid
Let’s say that we have a character at position (3, 2) and a target at position (6, 5) on a hex grid. To find the line of sight between the character and the target, we would follow these steps:
- Convert the coordinates to the same grid system. Both the character and the target are already using the same grid system, so no conversion is necessary.
- Draw a line between the character’s position and the target’s position. This can be done by connecting the two sets of coordinates (3, 2) and (6, 5) with a straight line.
- Determine the slope of the line. Using the formula from earlier, we get:
- Check the slope of the line against the hex grid. Since the slope of the line is exactly 1, the line passes through the top-left and bottom-right diagonals of each hex.
- Determine whether the line passes through any obstacles. In this case, we’ll assume that there are no obstacles between the character and the target, so the character has line of sight to the target.
m = (5 - 2) / (6 - 3)
m = 3 / 3
m = 1
Finding line of sight on a hex grid with coordinates is a crucial skill for any grid-based game. By following the steps outlined in this article, you should be able to quickly and accurately determine line of sight for any character on a hex grid. With a little practice, you’ll be able to master this skill in no time.
References
| Title | Author | Publication Date |
|---|---|---|
| Hex Grids | Red Blob Games | 2021-01-01 |
| Line of Sight | Game Developer | 2021-02-01 |