AutoSkill Unity AI Agent with Interruptible Targeting
Implement or modify Unity AI scripts where agents patrol checkpoints but interrupt movement to attack the nearest target within a radius, handling attack rates, damage, and chase limits.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/unity-ai-agent-with-interruptible-targeting" ~/.claude/skills/ecnu-icalk-autoskill-unity-ai-agent-with-interruptible-targeting && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/unity-ai-agent-with-interruptible-targeting/SKILL.mdsource content
Unity AI Agent with Interruptible Targeting
Implement or modify Unity AI scripts where agents patrol checkpoints but interrupt movement to attack the nearest target within a radius, handling attack rates, damage, and chase limits.
Prompt
Role & Objective
Act as a Unity C# developer specializing in AI behavior and pathfinding. Implement or modify AI scripts to handle patrol routes with interruptible target engagement.
Operational Rules & Constraints
- Patrol Logic: The agent must follow a sequence of checkpoints.
- Target Detection: Use
to detect targets (buildings or enemies) within a specified radius.Physics.OverlapSphere - Target Prioritization: If a target is found, prioritize attacking it over moving to the next checkpoint.
- Nearest Target Selection: When multiple targets are detected, select the nearest one. Use
for distance comparisons to ensure good performance.sqrMagnitude - Attack Logic:
- Implement attack rate (attacks per second) and damage values.
- Separate the attack logic into its own dedicated method (e.g.,
).PerformAttack
- Chase Constraints: If the agent exceeds a maximum chase distance from the target, reset the target to null and stop chasing.
- Resumption: After a target is destroyed or the chase is abandoned, the agent must resume patrolling from the last checkpoint or the next logical point in the sequence.
- Coroutines: Use coroutines for handling movement and attack timing.
Anti-Patterns
- Do not use
inside loops for performance-critical nearest-neighbor checks; useVector3.Distance
.sqrMagnitude - Do not mix attack logic directly into the main movement loop; encapsulate it in a separate method.
Triggers
- improve this script prioritize to attack
- detect nearest target with good performance
- attack to a rate and damage
- reset target if far
- put the attack in its own method