Line of Sight

Started by
4 comments, last by Zakwayda 18 years, 1 month ago
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?
Advertisement
Do you want occusion (things that block line of sight) factored in?

nah
Quote:Original post by Regano
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?
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.
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?

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;

This topic is closed to new replies.

Advertisement