def calculate_wall_avoidance(self, walls): self.whiskers = util._create_whiskers(self.pos, self.heading) #variables for keep track of tallys distance_to_intersection_point = 0 distance_to_closest_intersection_point = sys.float_info.max closest_wall = None force = Vector2() point = Vector2() closest_point = Vector2() # for each whisker find the closest wall for whisker in self.whiskers: for wall in self.world.walls: intersects,distance,intersecting_point = util.line_intersection_get_distance_point(Vector2(self.pos), whisker, wall.point1, wall.point2) if intersects: if distance < distance_to_closest_intersection_point: distance_closest_intersection_point = distance closest_wall = wall closest_point = intersecting_point # if we found a wall then calculate a steering force based on how far # the whisker penetrated the wall if closest_wall != None: over_shoot = whisker - closest_point force = wall.normal * over_shoot.length() * WALL_REPEL_FORCE return force