Solving the Frozen Units Problem: Retargeting After Death
Solving the Frozen Units Problem: Retargeting After Death
Author: Miguel Martinez Olivares
Posted on 08/18/2023
The Problem
During this week of development, I encountered a significant problem related to the retargeting system in our game. When a unit died, other units targeting it would freeze, unable to move or find new targets. This was because they still had a reference to the destroyed unit. This issue was causing a noticeable disruption in gameplay, leading to confusion and frustration for the players. The units' inability to retarget after an enemy's death was hindering the core combat mechanics and needed to be addressed urgently.
Problem Solution
The root cause of this issue was the lingering reference to the destroyed unit within the targeting system. When a unit died, the reference was not being removed, causing other units to freeze as they were still trying to target a non-existent object.
To solve this problem, I implemented a delegate that gets called when a unit dies. This delegate is responsible for removing the reference to the dead unit from any other units that were targeting it. By doing so, the units are then free to look for other targets or continue moving towards their destination points.
Here's a brief overview of the solution:
- Identify the Dead Unit: When a unit dies, the delegate is triggered, identifying the dead unit.
- Remove References: The delegate then searches for any units that were targeting the dead unit and removes the reference.
- Enable Retargeting: Without the lingering reference, the units can now retarget and continue their normal behavior.
This solution not only resolved the freezing issue but also made the combat more dynamic and responsive. Units now smoothly transition from one target to another or continue on their path if no targets are available. Testers have reported a significant improvement in the gameplay experience, and the combat feels more fluid and engaging.
By addressing this problem, we've enhanced the overall user experience and taken a significant step towards polishing our game. The retargeting system now works as intended, and the units' behavior aligns with our design goals.
TODO
One aspect of the retargeting system that still requires fine-tuning is the units' behavior when sticking to a target. Currently, units may focus on their initial target even if another enemy unit passes closer to them. This can sometimes lead to unnatural or unexpected behavior in the game.
To address this, I'm considering enhancing the retargeting system to allow units to search for and switch to a closer target. This would make the AI more responsive to the dynamic changes in the battlefield, potentially leading to more engaging and realistic combat scenarios.
We plan to test both the current system and the proposed improvement, comparing how they affect gameplay. Our final decision on the AI's behavior will be based on what makes the game more fun and aligns best with our design goals.
Comments
Post a Comment