Player Skills System (Example Implementation)
Player Skills System (Example Implementation)
Note: The Player Skills system included with Enemy Masses is intended as a high-performance example implementation for "Survivor-style" or "Horde-mode" games. While fully functional and optimized for thousands of units, it is not a replacement for a dedicated RPG ability system (like Game Creator or RPG Builder).
This module is subject to change or may be moved to a separate optional package in future updates based on user feedback.
Overview
Enemy Masses includes a specialized skill system designed to handle the unique performance challenges of fighting massive crowds.
In a typical game, a projectile might check for collisions using Unity's physics engine. However, checking collisions against 5,000 individual colliders every frame is extremely expensive.
The Player Skills System solves this by using a Spatial Hashing / Caching approach:
The
PlayerSkillManagermaintains a lightweight cache of enemy positions, updated at a fixed interval (e.g., 10 times per second).Skills query this cache mathematically (e.g., "Give me all enemies within 5 meters") instead of using Physics.OverlapSphere.
Damage is applied directly to the crowd data structures, bypassing overhead.
Player Skill Manager
The PlayerSkillManager is the central brain. Attach this component to your Player GameObject.
Key Settings
Crowd Controllers: The manager needs to know which crowds to target. It can Auto Find them at runtime (recommended), or you can assign them manually.
Enemy Cache Update Rate: How often (in seconds) the spatial grid is rebuilt.
Lower values (0.1s): More accurate targeting, higher CPU cost.
Higher values (0.3s): Better performance, but fast-moving enemies might be slightly "out of sync" for targeting.
Max Tracked Agents: Limits the number of enemies processed for targeting.
0means unlimited.Global Max VFX Per Activation: A critical safety feature. If a skill hits 500 enemies at once, spawning 500 blood particle systems will freeze the game. This setting caps the visual effects (e.g., only show the first 20 hits) while still dealing damage to all 500.
Events (C#)
The manager exposes C# Actions for easy integration with UI, Sound, or XP systems:
OnEnemyDamaged(int damage, float healthRemaining, BaseSkill source)OnEnemyKilled(int enemyIndex, BaseSkill source)OnSkillLevelUp(BaseSkill skill)
Included Skills
The package includes several template skills that demonstrate different targeting patterns. You can use these as-is or duplicate them to create your own.
1. AoE Pulse Skill
Creates circular zones of damage.
Patterns: Around Player (Garlic style), Random Zones, or Targeted at Enemy Clusters (Holy Water style).
Features: Configurable tick rate, duration, and knockback.
2. Projectile Skill
Fires moving projectiles that travel in a straight line.
Targeting: Nearest Enemy, Random Direction, or Mouse Direction.
Features: Pierce count (hit multiple enemies), bounce, and homing capabilities.
3. Chain Lightning
Hits a primary target and then "jumps" to nearby enemies.
Features: Configurable jump count, jump range, and damage falloff per jump.
4. Beam Skill
Fires a continuous laser beam.
Features: Can rotate (like a lighthouse) or lock onto targets.
5. Orbiting Skill
Spawns projectiles that rotate around the player at a fixed distance (Bible style).
Features: Configurable rotation speed, radius, and expansion/contraction.
6. Rain Skill
Spawns damaging zones or projectiles from the sky.
Features: Good for "Blizzard" or "Meteor Shower" effects.
7. Nova Skill
Releases an expanding ring of projectiles or damage.
Features: Classic "Nova" or "Shockwave" behavior.
8. Spiral Skill
Fires projectiles in a spiral pattern outward from the player.
9. Passive Aura
Applies a constant effect to enemies within range without visual projectiles.
Features: Useful for "Slow Auras" or "Fear Auras".
Creating Custom Skills
To create a custom skill, create a new script that inherits from BaseSkill and override the OnActivate method.
Performance Tips
VFX Limits: Always keep
Global Max VFX Per Activationreasonable (e.g., 20-50). You rarely need to see more than 50 hit effects in a single frame.Cache Rate: For games with slow-moving zombies, an
Enemy Cache Update Rateof0.2or0.3is often indistinguishable from0.1but saves significant CPU time.Only Cache Alive: Keep
Only Cache Alive Agentsenabled. There is no reason to target dead bodies in a Survivor game.
Last updated