• 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!

Enemy Line of Sight

K

Kijjum

Guest
I'm making a top-down sneaking game with visible lines of sight. I have it so if you're behind a wall, you can't be seen... but the sight cone is still drawn in the area that is not active.

This is what I have inside the enemy step event:

//Collision Line
if collision_line(x,y,obj_Player.x+-16,obj_Player.y+-16,obj_Wall,1,0) < 1 && scone.char_collision = true
{
show_message("You've been caught!");
room_restart();
}
scone.char_collision = false;


What I have:


What I want:


Any ideas on how to fix this? Or even if I would need a completely new approach?
 
M

Maximus

Guest
should work, maybe change the <1 to ==noone. Also, why do you have the +-16? Are you trying to check 2 positions or a range at once?

Code:
//Collision Line
if collision_line(x,y, obj_Player.x, obj_Player.y, obj_Wall,1,0)  == noone && scone.char_collision = true
{
    show_message("You've been caught!");
    room_restart();
}
scone.char_collision = false;
Instead of doing lots of precise collision checking (slow and should be avoided) it would probably be better to define the view as a range and angle and check against these. As for drawing the view cone like in the screen shot that would be a little more difficult.
 
A

anomalous

Guest
You should look up LOS, light/shadow raycasting. Plenty of examples and code.
However, its very advanced and gets complicated quickly, especially if you want it to look polished. Since its just for a visual effect and wont actually affect the stealth...I would consider designing to avoid it. I know that "knowing where the opponent can see" may be a game mechanic for you..but that's just how it is.

You could have something to show the opponents general facing...without the big cone.
You could also have something that shows if the player is in LOS or not, and give them very little time to hide...etc. Lots of ways to design a similarly engaging system without needing raycast madness.

From experience, the fastest and cleanest method involved turning all obstacles into line segments, joining all adjacent line segments, and then drawing rays to all corners in light of sight using triangle primitives. Same system used in Monaco (drawing to all corners). You will have to optimize the heck out of it to get it to run acceptably.
 
K

Kijjum

Guest
You could have something to show the opponents general facing...without the big cone.
You could also have something that shows if the player is in LOS or not, and give them very little time to hide...etc. Lots of ways to design a similarly engaging system without needing raycast madness.
I might just go with something like that. I was doing a little bit of research on raycasting and it seems like sort of a pain:bash:. Thanks to everyone who replied btw <3
 
K

Kijjum

Guest
should work, maybe change the <1 to ==noone. Also, why do you have the +-16? Are you trying to check 2 positions or a range at once?
Yeah I'm using a circular character and to be seen behind walls you need to check for the edges of it which is +-16
 
M

Maximus

Guest
Yeah I'm using a circular character and to be seen behind walls you need to check for the edges of it which is +-16
+-16 doesn't mean "plus or minus 16" it means "plus negative 16". You are only checking one point when doing that.
 
K

Kijjum

Guest
+-16 doesn't mean "plus or minus 16" it means "plus negative 16". You are only checking one point when doing that.
Are you sure? I've done a few tests and when I walk out from behind a wall "plus negative 16" would mean that the back side of my character would have to be exposed to be caught, but I found that any part that is exposed gets seen... :0
 
Top