Jump to content
  • Advertisement
Sign in to follow this  
Regano

Line of Sight

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
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 this post


Link to post
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;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!