Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Day Three:

Added an Area2D node to the enemy to represent their range of vision. I figured out how to get the signal system to connect, so now the enemy now has an 'objects_in_range' array and bodies are added and removed from that list as they enter and leave the Area2D.

Went on to add ray-casting so that if a player is hiding behind a wall or obstacle, the enemy cannot see them.


But of course, I want to be able to change the shape of the enemy's vision cone, which means I need to do some more vector math to find which corners are blocking LOS, and then locate the points that represent the new polygon:

That's some progress! I've found edges of what's being blocked, and drawn lines for myself to represent as much. But using this method, I'm not calculating the inner corners that the enemy can see, and I also found that if the player stands between the enemy and his los of the center of the wall, the enemy thinks it can't see ANY of the wall. Also, two wall tiles placed next to each-other produce to extra lines along inside the wall that aren't useful. As you can see:

So I tried completely rewriting this code to see if I could address those issues, with some success:


Player movement is still interfering with calculating these points in unexpected ways, but as long as the player isn't in the way, I have the points I need to redraw the field of vision (but I have no idea if they are in the proper order, or how to sort them!) Hopefully soon I can achieve the following:

But that's for another day. Right now, my brain hurts from all the maths so I bid you adieu!

(+2)

Hey! It's good to see another Godot developer. This is really interesting and helpful for the future so thanks!

A quick thought: Have you thought of using a collision polygon2d or collision shape2d a little outside of the walls (in the areas the enemy shouldn't see). So when the player enters it a signal is sent to the enemy that indicates that they cant see the player. I'm not sure if this helps or not but I hope it does. Good luck on your project!

(+1)

Thank you!

Right now I'm using an Area2D RectangleShape2D to mark the area of the wall, and then casting an intersection ray from the guard to the player. If the ray hits the wall before the player, it lets the guard know that they can't see the player yet, but if it hits the player then the guard knows they can see the player.

When the whole cone color changes from blue to red, that's my visual indication for debugging that the guard sees the player.

The whole business of redrawing the cone so it's shape reflects what can and can't be seen by the guard is what has me stumped. But I think I'm just going to set that idea aside and work on getting the other game-play mechanics in place.