Range Challenge



func Player_is_in_LOS():
	var space = get_world_2d().direct_space_state
	var LOS_obstacle = space.intersect_ray(global_position, Player.global_position, [self], collision_mask)
		
	if LOS_obstacle.collider == Player and (Player.global_position.distance_to(global_position) < MAX_DETECTION_RANGE):
		return true
	else:
		return false

Same code just a few less variables.

Nice work on the visual tweaks!

About the code:
In general I prefer to have variables which describe what’s in them instead of having long lines of code that take a while to make sense of.
Of course it really is a matter of taste and in this case I do agree with you, the code is understandable enough, so I prefer your version to the one in the course.

1 Like

Privacy & Terms