Longship
Longship copied to clipboard
[Optimization] Optimize GetCharactersInRange
Another instance of #6 but with characters. Again, Bruteforce usage, should use a geohash instead.
Class: Character
public static void GetCharactersInRange(Vector3 point, float radius, List<Character> characters)
{
foreach (Character character in m_characters)
{
if (Vector3.Distance(character.transform.position, point) < radius)
{
characters.Add(character);
}
}
}
Apply the same for
public static bool IsCharacterInRange(Vector3 point, float range)
{
foreach (Character character in m_characters)
{
if (Vector3.Distance(character.transform.position, point) < range)
{
return true;
}
}
return false;
}
in the same class