Jump to content

  • Log In with Google      Sign In   
  • Create Account


Field of view check


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 wildboar   Members   -  Reputation: 281

Like
0Likes
Like

Posted 23 March 2013 - 12:48 PM

I have a small function:

 

 

 

bool CanSee(UnitInstance * Me, Vector3& Him)
{
   Vector3 NN1 = Me->Pos - Him;
   Vector3 NN2 = Me->PrevVel;

   NN1.normalize();
   NN2.normalize();

   return(Vector3::dot(NN1, NN2) < 0.0f);
}

This gives me too wide of a field of view check, this is between enemy and player used for stealth system.

How can I make it a lesser FOV?



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5092

Like
0Likes
Like

Posted 23 March 2013 - 01:31 PM

I don't understand why you use velocity for this. If your velocity is zero, you can't normalise it.

 

Normally a FOV check is done by taking the dot product between your (normalised) relative position from an enemy and their facing direction.

 

The dot product of 2 normalised vectors returns the cosine of the angle between them (angle is in radians of course), the check is normally something like

 

if(dot(normalisedRelativePosition, enemyFacing) >= cos(HalfAngleOfVisionConeInRadians)) /* in cone of vision */;

 

The check uses >= since with a 0 radian view angle you are only visible if your position is dead ahead of the enemy facing (i.e. the dot product is 1, which is cos(0)), and if the angle is pi then you are always in the cone of vision (since cos(pi) = -1).

 

EDIT: Note - the cone angle is the half angle (i.e. angle from the direction vector to the cone edge).

 

EDIT2: Several corrections ;)


Edited by Paradigm Shifter, 23 March 2013 - 01:39 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 wildboar   Members   -  Reputation: 281

Like
0Likes
Like

Posted 23 March 2013 - 02:47 PM

Thanks for the info

 

PrevVel is actually a velocity vector for the main player, it is assumed to be above 0.



#4 Paradigm Shifter   Crossbones+   -  Reputation: 5092

Like
1Likes
Like

Posted 23 March 2013 - 03:55 PM

Oh I see, you are using your velocity as your facing, and the cone check is for you being able to see the enemy... is that what you want?

 

What I said still applies anyway, use the cosine of the half cone angle. Since you calculated the vector from the enemy to you, which is opposite direction to the facing if the enemy is in front of you, reverse the sign of the dot product check so use <= instead of >=.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS