• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Creating a Field of View

GM Version: Gamemaker Studio 2
Target Platform: N/A
Download: N/A
Links: N/A

Summary:
Using a combination of lengthdir_x/y we can have any object shoot a ray out of their position and check to see what is in front of them, or beside them. We can transform this into a field of view and determine if we find a player object, or solid wall.

You can use this strategy to create walls that an enemy could not see through, or create a "window" where their vision could see through.

Video:
 

johnwo

Member
Nice tutorial!

The raycasting could be optimized by using collision_line. If a collision is found, simply use collision_line again, cutting the line in half every time, until the point of collision is found.
Essentially a binary search; it would cut the worst case time down from O(n) to O(log(n)).
 
Top