Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actor grabbing method #55

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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