Advertisement

Unity C# Field of View 2D Shadow Casting Algorithm

Started by July 12, 2021 05:23 PM
0 comments, last by Sehnsucht 3 years, 3 months ago

Hello good people! I've been bashing my head against the wall for the past few days trying to figure out how to fix my code.

Link to code: https://hatebin.com/sewqnebmiy

If you're familiar with shadowcasting, I'm working with only 1 octet as of right now until I get it 100%.

Below photo: The checkered patterned area is actually a solid wall. For some reason I cannot get it to reveal all of them. I haven't a clue as to why this is, Stepping through my code, I traverse from top to bottom via columns starting from the player. When i Hit a wall i recursively call the function with a new parameter for botslope(minimum slope) I then set the current iterations top slope to calculate from the player to the bottom right corner of the wall. I have a value called tolerance that i can tweak which will set how far in or out of the square to pull my calculations from.(ie, .5 is the very edge. I can tweak this value and make those walls appear but the calculations are less accurate. which brings me to my second photo/problem.

As you can see below, I should NOT be able to see that square, but since its slope is ≤ top slope it is revealed. This error is coming from the recursive call. Again increasing the tolerance value(bringing out where we calculate slope from) fixes this in some cases but not others.) Please send help! lol

This topic is closed to new replies.

Advertisement