amethyst / bracket-lib

The Roguelike Toolkit (RLTK), implemented for Rust.
MIT License
1.54k stars 111 forks source link

Field of View looking 'around corners' from some positions but not others #298

Closed KezleyHiggins closed 2 years ago

KezleyHiggins commented 2 years ago

Hi! I've followed the RLTK tutorial you wrote and am now working on making the final product that you show one how to make my own. However I have noticed that the way that the field_of_view method calculates what tiles it can see from different points has resulted in some situations that seem strange to me.

Using RLTK verbiage - if a goblin is stood right next to one side of a corner and the player is diagonally away from the corner then there are situations where the player can see the goblin around the corner, but the goblin cannot see the player. And the only time that the goblin will interact with the player is when you get right next to them around the corner.

This makes the field_of_view feel strange, as I don't know how in that situation one angle can give an entity the ability to "look around the corner" while the other entity can't when the same shape (the wall) is blocking their view. Is there a fix to this available?

Anders429 commented 1 year ago

I've noticed this as well. I spent a long time debugging my code and matching it against the rust roguelike tutorial, because I saw enemy behavior working differently in the online examples (see this example, where enemies follow around corners). I've concluded that the behavior of field_of_view() has changed since that tutorial was written, and it seems to have resulted in a loss of sight around corners.

I suspect the change in behavior came with https://github.com/amethyst/bracket-lib/commit/83afcd256981a5c0cea1c041b86b4c46366f0d6f, as this changed the algorithm itself and occurred after 0.8.0 (which the RLTK tutorial uses) was released.