I was wondering if someone could help me out with a problem. I’m not really sure where to begin in implementing it, so this is more of a question of concept then it is of actual code. If I know what I need to write, I’m usually decent at being able to do it. Any help would be great. Here’s the problem:
I want to be able to search for objects (like the player) over a preset 2D distance and shape based on the rotation of whatever is searching. I have three base VisionTypes that the AI will be able to have, which are the following:
- limitedFrontal: Can only see in a 90 degree angle (cone/triangle) in-front of itself
- fullFrontal: Can only see in a 180 degree angle in-front of itself
- complete: Can see everything around it.
Everything in my game is already in a grid based formation, similar to a chess game. Only one object can be on a single cell in the grid at a time, and it is turn based. Overall, what I want is that when it’s an AI’s turn, they look around based on their set VisionType and see if there is anything around that it cares about. If there is, then set itself up to move towards it, if possible. Obviously I would also need to take walls and other obstacles into account for the vision. The Pathfinding part is already done, so overall I just need it to be able to actually find something and then set a course based on the cell that the thing of interest is on.
I just don’t know how to do this. Is there some sort of Raycast function that casts over more than just a single point/line? If not, how would I obtain such a functionality?
Basically, limitedFrontal Vision would essentially be a 2D Triangle, where the upper tip is the point of origin, spreading outward over a range. fullFrontal Vision would essentially be a 2D Rectangle where the center of a side would be the point of origin, spreading outward over a range. Complete would be a 2D Square, where the point of origin would be the center of the square and it would spread outward in all directions.
Anything caught inside of these would be inspected for interest based on the object that cast the view. For example, a monster wouldn’t really care about other monsters of the same type, but might care about a rival monster type or the player, and seek them out and attempt to attack them.
Any thoughts on how to implement this would be great. Thanks in advance.