• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Custom sight field

Status
Not open for further replies.
Level 9
Joined
Apr 19, 2011
Messages
447
Hi there.

I'm trying to implement in my proyect a custom sight field for the enemies.
Basicly, the enemy will only be able to see your character if he is inside a certain cone of sight before him.

Please, look at the attached picture, I think it's better explained there.
The red dot, in the middle of the circle, it's the enemy.
The blue dot is the character (consider it's position as an arbitrary position).
The enemy will ONLY be able to see and chase the character if he is inside the area covered in green color, with a radius of D.
As you see, this area goes 60 degrees to the right of the enemy's facing, and 60 degrees to the left. It's a 120 degrees sight range.

In order to check if the character is in the desired region, I first checked if the character is inside the circle (radius D). That's the easy part.
The problems started appearing when I try to check if the character is in the green area.
This is what I've done:


  • Sight
    • Acontecimientos
      • Tiempo - Every 0.50 seconds of game time
    • Condiciones
      • (Distance between (Position of Enemy) and (Position of Character)) Menor que o igual a D
    • Acciones
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • Si: Condiciones
          • ((Angle from (Position of Enemy) to (Position of Character)) Menor que o igual a ((Facing of Enemy) + 60.00)) and ((Angle from (Position of Enemy) to (Position of Character)) Mayor que o igual a ((Facing of Enemy) - 60.00))
        • Entonces: Acciones
        • Otros: Acciones
OK. If the facing of the enemy is between 0 and 180 degrees, it works. If it's between 180 and 360 degrees, it doesn't.
I'm not very good with triggers; maybe there's a much more simpler way to do this. Maybe I'm missing something important. Maybe I just went mad with those angles... :vw_death:

Anyway, can someone help me fix this? Thanks in advance.

Regards
 

Attachments

  • visionfield.png
    visionfield.png
    21.7 KB · Views: 93
Level 9
Joined
Apr 19, 2011
Messages
447
The enemy is computer-controlled (my proyect is single player).
The enemies will be scattered through the maps, moving randomly in certain areas, and with this cone-shaped sigth range, the player could try to sneak some enemies, and avoid engaging in combat with too much powerful foes.

So, it could be said that this is some kind of player-finding AI.

Regards
 
Level 9
Joined
Apr 19, 2011
Messages
447
Code:
Minimum(Modulo(Absolute(alpha - beta), 360°), Modulo(360° - Absolute(alpha - beta), 360°)) <= 60°

I see, that looks good, but what exactly are the "alpha" and "beta" angles?
Also, I find kinda difficult to understand that code. Could you please explain with more detail the logic of the code? I don't just want to copy a code and use it... I wan't to understand it.

Thanks for answering.

Regards
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
alpha, beta are the angles, one is facing of enemy, the other angle between enemy and character, does not matter which is which.

(alpha - beta) is the brute difference of these two numbers.

The result could be negative but then the distance we want is the inverse of it. Infact, it should be the same whether we go from alpha to beta or the other way around.

Modulo ensures that the angles are in the same period to be able to match them.

And the minimum function is there because (alpha - beta) could be greater than 180° but then we would like to take the other direction, the shorter path.

Maybe there are better solutions. I actually just copied it from my math library that I have written somewhen in the past.
 
Status
Not open for further replies.
Top