Made a debug view and found slight problems

Since I spent way too much time on this, I thought I might share it in case anyone else is interested:
I was fairly sure that the light cone does not line up with the actual area that is used for player detection in the rest of the code.
So I wrote some debug drawing code and found out that there are tiny differences between what you see and what is considered a player detection, but the difference is neglegible for the gameplay, I guess.

The biggest problem is that we’re using the only the center point of the Player for detection instead of the collision shape, but most of the time that just cancels out the error of the wider detection area. Maybe Yann corrects this stuff in a later lecture, I still have a few ahead of me. If not, I guess I’ll try to solve this when the course work on the project is finished.

You can try it out for yourself by adding this code to your

# You have to call update() in your _process() otherwise this doesn't work properly!
# Don't ask me why, it's just what the docs said.

func _draw():

func debug_draw_line_to_Player():
	var to_Player = ((Player.position - global_position).normalized() * MAX_DETECTION_RANGE).rotated(-global_rotation)
	draw_line(position, to_Player, $Torch.get_color(), 3.0)

func debug_draw_observed_area(center, radius, angle_from, angle_to, color):
    var nb_points = 8
    var points_arc = PoolVector2Array()
    var colors = PoolColorArray([color])

    for i in range(nb_points+1):
        var angle_point = deg2rad(angle_from + i * (angle_to - angle_from) / nb_points - 0)
        points_arc.push_back(center + Vector2(cos(angle_point), sin(angle_point)) * radius)

    draw_polyline_colors(points_arc, colors, 2)

Privacy & Terms