• Create Account

We're offering banner ads on our site from just \$5!

### #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;

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
}


### #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;

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
}


### #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;

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
}


### #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;

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;
}


### #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;

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;
}


### #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;

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;
}