float CalculateDistance(D3DXVECTOR3 enemyPos, D3DXVECTOR3 playerPos)
{
float length;
float distanceX;
float distanceZ;
distanceX = enemyPos.x - playerPos.x;
distanceZ = enemyPos.z - playerPos.z;
length = sqrt((distanceX*distanceX) + (distanceZ * distanceZ));
return length;
}
//And then in my Update
D3DXVECTOR3 distance = D3DXVECTOR3(10.0f, 0.0f, 10.0f);
if (distance.x || distance.z <= CalculateDistance(D3DXVECTOR3(position.x, 0.0f, position.z), D3DXVECTOR3(CGame::GetPlayer()->GetPos().x, 0.0f, CGame::GetPlayer()->GetPos().z)))
{
int Random = rand() % 50;
if (Random == 0)
{
D3DXVECTOR3 towardsPlayer = CGame::GetPlayer()->GetPos() - position;
Bullet::CreateBullet((D3DXVECTOR3(position.x, position.y - 5.0f, position.z)),
D3DXVECTOR3(10.0f, 10.0f, 0.0f),
25.0f,
towardsPlayer,
30,
BULLET_TYPE_ENEMY);
}
}
I've tried doing this. The enemy continues to shoot even if I'm farther than distance.x and distance.z. Can someone tell me what's wrong?
↧