Line of Sight
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?
Quote:Original post by ReganoHere's some pseudocode:
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?
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 ReganoThat's meant to be the copy constructor. You could also write it as: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?
Vector2 v1 = c*forward+s*side;Vector2 v2 = c*forward-s*side;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement