Skip to content

Conversation

@MaxArchxd
Copy link

Added DangerousAreaScanner, a script to scan a potentially dangerous area for dangerous obstacles upon entering.

Added DangerousAreaScanner, a script to scan a potentially dangerous area for dangerous obstacles upon entering.
@SorraTheOrc SorraTheOrc requested a review from Copilot June 10, 2025 06:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a DangerousAreaScanner script that allows an agent to detect potentially dangerous areas and obstacles while navigating a scene. It also includes a new TestAgentScript for basic navigation and enhances obstacle collection with ObstacleListSingleton.

  • Introduces DangerousAreaScanner with scanning logic and delay handling.
  • Provides ObstacleListSingleton for grouping obstacles by tag.
  • Adds TestAgentScript for demonstrating NavMeshAgent destination setting.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

File Description
Assets/Wizards Code/MaxArchxd/Scripts/TestAgentScript.cs New script to set the destination for a NavMeshAgent.
Assets/Wizards Code/MaxArchxd/Scripts/ObstacleListSingleton.cs Singleton for aggregating obstacles and filtering them by tag.
Assets/Wizards Code/MaxArchxd/Scripts/DangerousAreaScanner.cs Main logic for scanning dangerous areas and processing obstacles.
Other *.meta and scene files Updated metadata to support the added scripts and scene configurations.

@SorraTheOrc SorraTheOrc self-requested a review June 10, 2025 06:11
Copy link
Member

@SorraTheOrc SorraTheOrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. This is an interesting idea. The implementation is a little confusing, with many one-line methods. I'm sure that this can be resolved easily enough.

The coding style doesn't match the rest of the project. Again, easily resolvable.

There are a number of recommendations for improvement inline.

void Update()
{
if (waiting) return;
timeSinceLastScan += Time.deltaTime;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be running as a Coroutine rather than an update as this will only run every 1s. This will also remove the need to track timeSinceLastScan.

return false;
}

private List<NavMeshObstacle> getRelevantObstacles()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably call this in Start() so as not to cause a CPU spike in a single frame on first test.


private List<NavMeshObstacle> getRelevantObstacles()
{
if (dangerousObstacles.Count == 0) return new List<NavMeshObstacle>(ObstacleListSingleton.Instance.ObstaclesInScene);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if an obstacle is added to or removed from the scene?

List<NavMeshObstacle> obstacles = getRelevantObstacles();
foreach(NavMeshObstacle obstacle in obstacles)
{
if(Vector3.Distance(obstacle.transform.position, transform.position) <= detectionRadius) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an expensive operation if there are a reasonable number of obstacles. Using SqeMagnituted would help a little but spreading this over multiple frames would help even more.

using WizardsCode.BackgroundAI;

[RequireComponent(typeof(NavMeshAgent))]
public class DangerousAreaScanner : AbstractSingleton<DangerousAreaScanner>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this would be better as a Sense (See LineOfSight as example) rather than a monobehaviour. Though this needs a little more thought before being sure about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should this really be a singleton? Doesn't that mean that it is impossible to have different collections of dangerous obstacles for different characters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants