I'm working on a TD game and I'm trying to write a code to check if the enemy enters the tower range to fire.
The problem is that the tower is shooting at the enemy even though the enemy is out of range (the red circle is the range)
here is a video that shows my problem.
[media]
[/media]
here what I have so far
Bullet::Bullet()
{
Radius = 100.0f;
}
void Bullet::CheckIfInRange()
{
DistanceX = tower.GetXPosition() - Enemy2.EnemyXPosition;
DistanceY = tower.GetYPosition() - Enemy2.EnemyYPosition;
if((DistanceX<= Radius && DistanceY<=Radius) || (DistanceX>= Radius && DistanceY>=Radius))
return true;
else
return false;
}