I'm having difficulties with checking if a gameobject is within a specific radius compared to the player.
My gameobject contains a radius and i want to use that for the checking yet i fail.
This is what i had so far:
public bool IsInRange(Vector2 currentTarget)
{
if ((currentTarget.X >= PosX - BRadius && currentTarget.Y >= PosY - BRadius) || // left up
(currentTarget.X >= PosX - BRadius && currentTarget.Y <= PosY + BRadius) || // left down
(currentTarget.X >= PosX + BRadius && currentTarget.Y >= PosY + BRadius) || //right up
(currentTarget.X >= PosX + BRadius && currentTarget.Y <= PosY - BRadius)) //right down
{
return true;
}
return false;
}
I'm trying to do this within C# using the XNA framework.
PosX and PosY are from the current gameObject his position. And the currentTarget is for now only the player's position.