# Line of Sight

This topic is 4642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm looking for a simple 2D solution to displaying a line of sight cone based on the enemies current position and viewing angle. Can anyone help me?

##### Share on other sites
Do you want occusion (things that block line of sight) factored in?

nah

##### Share on other sites
Quote:
 Original post by ReganoI'm looking for a simple 2D solution to displaying a line of sight cone based on the enemies current position and viewing angle. Can anyone help me?
Here's some pseudocode:
Vector2 forward(cos(enemy.directionAngle), sin(enemy. directionAngle));Vector2 side(-forward.y, forward.x);float fov = enemy.fieldOfView * 0.5f;float c = cos(fov);float s = sin(fov);Vector2 v1(c*forward+s*side);Vector2 v2(c*forward-s*side);
v1 and v2 now represent the edges of the line of sight cone. To draw the cone, simple draw two lines starting at the enemy position and in the direction of v1 and v2 respectively.

Let me know if anything is unclear.

##### Share on other sites
Quote:
 Vector2 v1(c*forward+s*side);Vector2 v2(c*forward-s*side);

Thanks for your help, is v1 and v2 supposed to have just one parameter?

##### Share on other sites
Quote:
Original post by Regano
Quote:
 Vector2 v1(c*forward+s*side);Vector2 v2(c*forward-s*side);

Thanks for your help, is v1 and v2 supposed to have just one parameter?
That's meant to be the copy constructor. You could also write it as:
Vector2 v1 = c*forward+s*side;Vector2 v2 = c*forward-s*side;

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633312
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×