This angle_to() code makes more sense to me

The following image and reordering of the angle calculations makes more sense to me.

I know the math is the same, but it makes more sense to me to calculate the angle from direction I’m facing to the direction at which the player is located.

My function looks like this:

func player_in_fov():
	var my_direction = Vector2(1, 0).rotated(global_rotation)
	var direction_to_player = (Player.global_position - global_position).normalized()
	var angle_to_player = rad2deg(my_direction.angle_to(direction_to_player))
	return abs(angle_to_player) < FOV_TOLERANCE / 2

I also left the FOV_TOLERANCE as the full field of view angle, since that value is more understandable as a constant than half the field of view.


That’s fair - naming variables sensibly is something I find tough, and your angle_to does make a lot of sense

thanks @DanielMcPherson good to see another view point.

This code gives me a more accurate result - my angle was off a few degrees. seems Yann you have player.position and it should be player.global_position

Privacy & Terms