Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualbelfegor

Posted 21 May 2013 - 05:57 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos = enemy.pos;
vec3 enemyDir = normalize(enemy.LookAt - enemyPos);
vec3 playerPos = player.pos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle < enemyConeAngle && distance < enemyZoneRadius)
{
    enemy.state = chase_player;
}
 
...
if(enemy.state == chase_player)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime; // move towards player
}

 

On top of my head, might made mistake somewhere.


#5belfegor

Posted 21 May 2013 - 05:56 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos;
vec3 enemyDir = normalize(enemyLookAt - enemyPos);
vec3 playerPos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle < enemyConeAngle && distance < enemyZoneRadius)
{
    enemy.state = chase_player;
}
 
...
if(enemy.state == chase_player)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime; // move towards player
}

 

On top of my head, might made mistake somewhere.


#4belfegor

Posted 21 May 2013 - 05:54 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos;
vec3 enemyDir = normalize(enemyLookAt - enemyPos);
vec3 playerPos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle < enemyConeAngle && distance < enemyZoneRadius)
{
    enemy.state = chase_player;
}
 
...
if(enemy.state == chase_player)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime; // move to player
}

 

On top of my head, might made mistake somewhere.


#3belfegor

Posted 21 May 2013 - 05:53 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos;
vec3 enemyDir = normalize(enemyLookAt - enemyPos);
vec3 playerPos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle < enemyConeAngle && distance < enemyZoneRadius)
{
    enemy.state = attack;
}
 
...
if(enemy.state == attack)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime;
}

 

On top of my head, might made mistake somewhere.


#2belfegor

Posted 21 May 2013 - 05:51 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos;
vec3 enemyDir = normalize(enemyLookAt - enemyPos);
vec3 playerPos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle > enemyConeAngle && distance > enemyZoneRadius)
{
    enemy.state = attack;
}
 
...
if(enemy.state == attack)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime;
}

 

On top of my head, might made mistake somewhere.


#1belfegor

Posted 21 May 2013 - 05:50 AM

It doesn't matter if it is 2d or 3d, you could use the same math

 

float enemyConeAngle = 0.6f;
float enemyZoneRadius = 10.0f;

vec3 enemyPos;
vec3 enemyDir = normalize(enemyLookAt - enemyPos);
vec3 playerPos;
vec3 toPlayerDir = normalize(playerPos - enemyPos);
 
float angle = acos(dot(enemyDir, toPlayerDir));
float distance = sqrt(dot(playerPos - enemyPos));

if(angle > enemyConeAngle )
{
    enemy.state = attack;
}
 
...
if(enemy.state == attack)
{
    float moveSpeed = 3.0f;
    enemy.pos += toPlayerDir * moveSpeed * deltaTime;
}

 

On top of my head, might made mistake somewhere.


PARTNERS