Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:03:07+00:00 2026-06-03T04:03:07+00:00

A weirrrrd problem I’m having here. I’ve implemented a field of view for my

  • 0

A weirrrrd problem I’m having here. I’ve implemented a field of view for my enemies, so that when the player travels inside the detectable area (120 degree cone in front) he gets chased by the bad guy until he gets outside the FOV.

Problem is there is a 120 FOV cone coming out of teh enemies back as well, so theres two cones, one in front, one behind, i only want to use the one in front. Only thing i can think of is I’m overflowing passed PI? I’m really not sure.

I used this tutorial to implement this using vector math. Dot product section.
http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/

here’s the code related to FOV.

 Vector2 EnemyVecAngle = new Vector2((float)Math.Cos(EnemyAnimation.Angle), (float)Math.Sin(EnemyAnimation.Angle));

        //normalize
        Vector2 EnemyFacingN = Vector2.Normalize(EnemyVecAngle);
        Vector2 EnemytoPlayer = Vector2.Normalize(player.Position - Position);

        //check angle
        float CheckAngle = (float)Math.Acos(Vector2.Dot(EnemyFacingN, EnemytoPlayer));

if ((CheckAngle >= 60) && (CheckAngle <= 120)
following = true;

this is the statement that makes the enemy face towards teh player once detected

EnemyAnimation.Angle = (float)Math.PI / -2 + (float)Math.Atan2(Position.Y - player.Position.Y, Position.X - player.Position.X);

i’m wondering why i need to add -PI/2 for it to work, i think this could be related to teh issue. Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:03:08+00:00Added an answer on June 3, 2026 at 4:03 am

    I think that add Math.PI / -2 is to rotate 90º the texture.

    You should use Atan2:

        Vector2 EnemyVecAngle = new Vector2((float)Math.Cos(EnemyAnimation.Angle), (float)Math.Sin(EnemyAnimation.Angle));
    
        //normalize
        Vector2 EnemyFacingN = Vector2.Normalize(EnemyVecAngle);
        Vector2 EnemytoPlayer = Vector2.Normalize(player.Position - Position);
    
        //check angle
        float CheckAngle = (float) (Math.Atan2(EnemyFacingN.Y, EnemyFacingN.X) 
                                  - Math.Atan2(EnemytoPlayer.Y, EnemytoPlayer.X) );  
    

    With that it should be enough… Atant2 will take care of the right angle sign…
    though you will inspect the new calculated angles to choose the adecuate range…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.