Enemies eyesight.
abdou0230
Member Posts: 4
I want to build a stealth game where the enemy can only spot the player if he sees him, the most I was able to achieve is to make an invisible line coming out of him and when it touches the player he starts chasing, but then I hit a roadblock when i tried to add objects for the player to hide behind.
I know there is a way to calculate the distance between the enemy and the player but that is not what I want, I want the enemy to notice the player only if he is moving towards his direction, and don't spot him if the players is hiding behind a crate or in the shadows. Any ideas ?
Comments
If you search for 'line of sight' in the forum you'll find some threads about the topic I'm sure.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Thanks Jamie ( I did leave you a similar comment on one of your videos by the way) So I did some research and found out that the easiest and best way that suit my needs is to create a line of sight in front or back of the enemy,for example when the enemy is moving right it will spawn the line in front of him, when he finishes moving the line will get destroyed (using a boolean) then the enemy moves to the left and it spawns the line in back of it, it works okay but I faced a problem when constraining the line x&y values to the enemies it always moves to the center of it instead of staying in front or back, I tried different offset methods but none of them worked.
So I tried some stuff and I reached the result I exactly wanted, but I'm not sure if my way is the most efficient way. Check the link: Download