Your mobile shooter: the enemy sees players through walls, reacts in 0.02 seconds — players leave after a day. Sound familiar? This is a typical mistake: lack of a perception system and a naive finite state machine. Our team with 5+ years of mobile game development experience solves this in 2–4 weeks. We combine Behaviour Trees, physically honest sensors, and Dynamic Difficulty Adjustment (DDA). Developing AI opponents is one of our core competencies. The result: an enemy that feels alive but does not cheat. In 5 years on the market, we have implemented AI for 15+ mobile games, reducing player churn by 20% on average.
Why Behaviour Trees for Complex Combat?
Behaviour Trees are a hierarchical structure of Selector, Sequence, Condition, and Action nodes. They are 3–5 times easier to scale than FSM: instead of a tangled state graph, a clear tree. With 10+ behaviors, BT speeds up debugging by 2–3 times. FSM works for 3–4 states (Patrol→Chase→Attack), but the graph explodes as complexity grows. BT is the choice for complex combat.
// Unity: simplified Sequence node public class SequenceNode : BehaviourNode { private List<BehaviourNode> children; private int currentIndex = 0; public override NodeStatus Tick(AIContext context) { while (currentIndex < children.Count) { var status = children[currentIndex].Tick(context); if (status == NodeStatus.Running) return NodeStatus.Running; if (status == NodeStatus.Failure) { currentIndex = 0; return NodeStatus.Failure; } currentIndex++; } currentIndex = 0; return NodeStatus.Success; } } We use parallel tasks for simultaneous actions (shooting + movement) and priority selectors for urgent situations (dodging a grenade). Each tick updates the Blackboard — a shared data store between nodes. This allows flexible state management without global variables.
How AI Sees the Player: Perception System
The key question is not "what does the enemy do," but "what does it know about the world." Without a proper perception system, a BT tree works with telepathy: the enemy knows the player's position through walls and reacts instantly.
Field of View — a vision cone with angle and distance:
bool CanSeePlayer(Transform enemy, Transform player, float viewAngle, float viewDistance) { Vector3 dirToPlayer = (player.position - enemy.position).normalized; if (Vector3.Angle(enemy.forward, dirToPlayer) > viewAngle / 2f) return false; float dist = Vector3.Distance(enemy.position, player.position); if (dist > viewDistance) return false; return !Physics.Raycast(enemy.position, dirToPlayer, dist, LayerMask.GetMask("Obstacles")); } Hearing — sound events through a queue: footsteps, gunshots, falling objects. Each event has a radius and attenuation. Memory — we remember the last known position and patrol it if we lose the target.
What is DDA and How Does It Adjust Difficulty?
Fixed difficulty is bad. Dynamic Difficulty Adjustment adapts behavior based on player performance. Parameters are loaded from a config — designers can change them without recompilation.
| Parameter | Easy | Medium | Hard |
|---|---|---|---|
| Reaction to player | 1.2 sec | 0.6 sec | 0.2 sec |
| View angle | 60° | 90° | 120° |
| Shooting accuracy | 40% | 70% | 90% |
| Patrol time | 8 sec | 5 sec | 3 sec |
DDA automatically shifts parameters based on the player's win rate over the last N sessions. This saves up to 30% of manual balancing time and keeps the player in the flow. Wikipedia: Dynamic game difficulty balancing
How to Ensure Performance on Low-End Devices?
AI ticks should not happen every frame. For 20 enemies on the scene:
| Optimization Method | Effect |
|---|---|
| BT Tick every 100–200ms | 40% CPU reduction |
| Raycast via LOD (distant enemies less often) | 50% physics cost savings |
| Pathfinding only when target changes | Smooth 60 FPS on 5-year-old devices |
Unity NavMesh works well on mobile, but recalculating paths for all agents in one frame causes a spike. We distribute recalculations via CoroutineManager or Job System. We guarantee stable 60 FPS on 5-year-old devices.
AI Opponent Development Process
- Analysis — study game mechanics, design document, behavior scenarios.
- Design — choose architecture (FSM/BT), design perception system, memory.
- Implementation — write code, integrate with navigation (NavMesh), tune parameters.
- Testing — playtesting: measure death rate, time-to-kill, win rate per level. Iterate.
- Deployment — hand over source code with comments, BT diagrams, configs. Train the team.
Each stage is documented. On request — integration into your CI/CD pipeline.
What's Included in AI Opponent Development
Within the project, you receive:
- Source code of the AI system in Unity C# or Godot GDScript with comments
- Documentation on the BT architecture and perception system (diagrams, configs)
- Integration with your navigation (NavMesh) and animations
- DDA parameter tuning for your game design
- Loadable configs (JSON) for quick designer iteration
- Team training (1-2 hours) on using and extending the AI
- Support during testing and post-release
Timeline Estimates
- Basic FSM opponent with patrol and pursuit — 3–5 days.
- Full system with BT, perception, DDA, and multiple enemy types — 3–6 weeks.
Exact cost is calculated individually after analyzing your game.
Contact us to get a consultation on AI architecture for your project. We will help you choose the optimal stack (Unity, Godot, Unreal) and avoid common pitfalls — AI cheating and performance drops.







