I am trying to make a lighting system that keeps track of where you have been by only lightly shading areas that you've seen and darkly shading anything you haven't seen and not shading where you are. The first issue I ran into was the fact that just using a regular circle allowed you to see through/over walls so I decided to raycast 16 points and have them stop when they hit a wall, take the position, make a polygon out of those points and then use that to detect the "fog of war" tiles. Here's my code for the raycasting and polygon generating script:
if position != oldPos:
var space_state = get_world_2d().direct_space_state
var collisionLengths =  # this is the array that will store the distance in all 16 directiosn
for theta in range(0,15):
#first it needs to define the vector two for the given angle.
var vector = Vector2(cos((theta+1)*RayAngle)*light,sin((theta+1)*RayAngle)*light)
#RayAngle is set to 22.5 degrees so that after 16 iterations it will have gone a whole circle.
var collision = space_state.intersect_ray(self.position,self.position+map.map_to_world(vector))
var v = VisionBody.instance()
for Vi in $VisionArea.get_children():
Vi.mode = RigidBody2D.MODE_STATIC
and this is the code for the referenced VisionBody:
var shape = ConcavePolygonShape2D.new()
position = pos
$CollisionShape2D.shape = shape
and Finally when I ran my program nothing was wrong with compiling but the segments all connected in a terribly:
and then this was it with a ray angle of 45 degrees and only 8 iterations I expected and even 8 pointed polygon.
If you read all of this you're truly a stalwart woman/man.
Edit 1: Minor Spelling Issues