Skip to content

Commit

Permalink
Merge pull request #55 from Exouxas/54-create-method-of-grabbing-near…
Browse files Browse the repository at this point in the history
…by-actors

Add actor grabbing method
  • Loading branch information
Exouxas authored Oct 20, 2023
2 parents 14f2eed + 1c36d50 commit bb87899
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Core/Worlds/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,31 @@ public void Move(Actor a, Vector3 v)
MoveTo(a, oldPosition + v);
}

/// <summary>
/// Get actors within range of the given center position and radius.
/// </summary>
/// <param name="center">The center position used for calculating the radius.</param>
/// <param name="radius">The radius used for calculating the range from the center position.</param>
/// <returns>A collection of actors within the range of the center position.</returns>
public ICollection<Actor> GetActorsInArea(Vector3 center, float radius)
{
List<Actor> actorsInArea = new();

lock (_actorLock)
{
foreach (Actor a in _actors)
{
if (Vector3.Distance(center, GetPosition(a)) <= radius)
{
actorsInArea.Add(a);
}
}
}

return actorsInArea;
}


public abstract void Start();
public abstract void Stop();
}
Expand Down

0 comments on commit bb87899

Please sign in to comment.