Cone of sight

Hi people i am new in here and i hope you can help me a little.

I am making a game for iphone where i would like the players to have a cone of sight. It should detect the presence of another player in its range.

I was thinking of using raycast, for the size of the sprites each one should have 5 raycast evenly distributed forming a cone. I was wondering if this was a valid option, if having 5 raycasts per sprite was too much, and if there is a better method i missed... ( like somehow create 2 raycasts - those would be the start and end of the cone and then calculate the area between them, don't know if this is posible and i think it would not work with obstacles in the middle...)

Thanks in advance,

Pablo
Ive found that simply checking if the angle of one player from another is within a certain range (determined by your player direction or whatever) and THEN doing a raycast to check line of sight is eaiser and also much more efficent than doing multiple raycasts, as you could get wierd responses at long distances with your method
You could also create the cone as a sensor shape and then listen to contact events to detect if the other play is inside the cone.
Good idea, you would still need a raycast for line of sight though
Hi guys! thanks, i thought about those two, both would work for detecting that the player is inside the pov of the enemy, what i can't figure out is where to do the raycast from and to:

Check this example:

Image

There, i am sure the enemy would have to see the player, but the raycast will hit the wall first...

A solution would be to raycast from the center of the enemy to the edges of the player and the center, but i would end with 3 raycasts per enemy this way.

Maybe i am trying to make it too much precise?
Hmm, possibly... I'm not sure, depends how precise you want it to be.

Original thread: https://box2d.org/forum/viewtopic.php?t=3502