Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Where is the fault in this angle detection?

Author
Message
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 19th Feb 2005 18:58
Hello all,

Let me set an introduction to the problem I am facing.
I have been experimenting with in-game a.i. for a month or so, and have come up with a few starting techniques, which work...partially. What I have written, is a 2D program using circles and lines, which includes a Player Character and what will be a Non-Player Character.

I have been experimenting on creating view limits and boundaries of the a.i., where it can only see so far out, and so far to it's sides. First, I judge the distance in between the Player Character and the Non-Player Character. If their distance apart is within 300 units then I calculate if the Player Character is within -45o and +45o of the Non-Player Character's current angle of direction, thus creating a limit to how far to each side the Non-Player Character can see. If so, the "inboundary" variable is set to 1 and "In Boundaries" is printed to the screen.

The problem is that if the Non-Player Character's current angle of direction is between the angles of 315o to 0o and 0o to 45o, though mathematically within these angles the Non-Player Character should detect the Player Character, it does not. In between 315o and 45o is the almighty 0o. I know this the problem, but why is it the problem, and how do you theorize it can be fixed?

Since I use #Include files which cradle my functions, I have attached a ZIP file of all my source code to run this program, which does not include any media and is only 319KB(compressed) in size. The file "driver.dba" is the one you need to execute to run the program. The file "ai_main.dba" is where the functions for Player Character detection are held. When the program is in "run-time", statistics are printed to the screen to help you help me figure this out. The controls are printed to the screen. Thank you, whoever takes their time to help me.

+NanoBrain+

Attachments

Login to view attachments
mathkid
20
Years of Service
User Offline
Joined: 1st Feb 2005
Location: Central Massachusetts
Posted: 21st Feb 2005 03:31
As a n00b to programming but not to mathematics, let me suggest something. Take the difference between the NPC's angle and the angle where the player. Take the absolute value. If that number is less than or equal to 45, or greater than or equal to 315, the player is in range.

Example:
NPC Angle: 10o
Player Angle: 350o (in range)

Difference=-340o
Abs(Difference)=340o

340o >= 315o so Player is detected!

NPC Angle: 30o
Player Angle: 70o (in range)

Difference=-40o
Abs(Difference)=40o

40o <= 45o so Player is detected!


Hope this helps.

Login to post a reply

Server time is: 2025-05-23 18:56:31
Your offset time is: 2025-05-23 18:56:31