Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualTiagoCosta

Posted 17 January 2013 - 11:38 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?

Simple math can probably be enough to do the vision cone check.
 

int fastVisibilityCheck(float4 playerPos, float4 enemyPos, float4 enemyLookDir,
                        float maxViewDistance, float cosHalfMaxAngle)
{
     //Vector from enemyPos to playerPos
     float4 view = playerPos-enemyPos;
     float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

     if(distance > maxViewDistance)
          return 0; //not visible

     view = normalize(view);
    
     //cosine of the angle between the view vector and the direction the enemy is looking
     float cosAngle = enemyLookDir dot view;

     //check if player is inside the cone
     if(cosAngle < cosMaxAngle)
          return 0; //not visible

     return 1; //visible
}

 

Use the previous function like this:

for(int i = 0; i < enemies.size(); i++)
{
     if(fastVisibilityCheck(player.pos, enemies[i].pos, enemies[i].lookDir, enemies[i].maxViewD, cos(enemies[i].fieldOfView/2)))
     {
          //use raycasting to check if enemy can really see the player
     }
}

 

 


#5TiagoCosta

Posted 17 January 2013 - 11:33 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?

Simple math can probably be enough to do the vision cone check.
 

int fastVisibilityCheck(float4 playerPos, float4 enemyPos, float4 enemyLookDir,
                        float maxViewDistance, float cosMaxAngle)
{
     //Vector from enemyPos to playerPos
     float4 view = playerPos-enemyPos;
     float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

     if(distance > maxViewDistance)
          return 0; //not visible

     view = normalize(view);
    
     //cosine of the angle between the view vector and the direction the enemy is looking
     float cosAngle = enemyLookDir dot view;

     //check if player is inside the cone
     if(cosAngle < cosMaxAngle)
          return 0; //not visible

return 1; //visible

#4TiagoCosta

Posted 17 January 2013 - 11:25 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?

Simple math can probably be enough to do the vision cone check.
 

float4 playerPos;
float4 enemyPos;
float4 enemyDir;

float4 view = playerPos-enemyPos;
float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

if(distance > maxViewDistance)
    return 0; //not visible

view = normalize(view);
float cosAngle = enemyDir dot view;

float cosMaxAngle = cos(45);

//check if player is inside the 90 degrees cone
if(cosAngle < cosMaxAngle)
     return 0; //not visible

return 1; //visible

#3TiagoCosta

Posted 17 January 2013 - 11:19 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?

Simple math can probably be enough to do the vision cone check.
 

float4 playerPos;
float4 enemyPos;
float4 enemyDir;

float4 view = playerPos-enemyPos;
float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

if(distance > maxViewDistance)
    return 0; //not visible

view = normalize(view);
float angle = enemyDir dot view;

float maxAngle = cos(45);

//check if player is inside the 90 degrees cone
if(angle < maxAngle)
     return 0; //not visible

return 1; //visible

#2TiagoCosta

Posted 17 January 2013 - 05:28 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?
Simple math can probably be enough to do the vision cone check.

float4 playerPos;
float4 enemyPos;
float4 enemyDir;

float4 view = playerPos-enemyPos;
float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

if(distance > someNumber)
    return 0; //not visible

view = normalize(view);
float angle = enemyDir dot view;

if(angle < someOtherNumber)
     return 0; //not visible

return 1; //visible

#1TiagoCosta

Posted 17 January 2013 - 05:25 AM

Can I create a cone shape starting from the enemy eyes to detect collision and once the collision is detected I do raycasting from the enemy eyes towards the player to check if the enemy got direct sight on the player?

 

Simple math can probably be enough to do the vision cone check.

 

float4 playerPos;
float4 enemyPos;
float4 enemyDir;

float4 view = playerPos-enemyPos;

float distance = sqrt(view.x^2 + view.y^2 + view.z^2);

if(distance > someNumber)
    return 0; //not visible

view = normalize(view);

float angle = enemyDir dot view;

if(angle > someNumber)
     return 0; //not visible

return 1; //visible

PARTNERS