Really recommend also adding a flag to disable the enemy attack during cut scenes/other times in this lecture. I created a guard that is specifically guarding the bridge. So my trigger volume was a little too close to this guard. Therefore, while the cinematic scene was playing, my player, which had it’s attacked disabled, was taking attacks from the enemy losing health. I found a way to solve this issue and make the game play more dramatic at the same time.
My Steps:
- Create a new tag “Enemy” assign all enemies to this tag. Update the prefab to include this change by assigning overrides.
- Update AIController to add a flag for “CanAttack”
public class AIController : MonoBehaviour
{
// … other fields …
public bool canAttack = true; // Add this flag -> default value true because this is a cinematic trigger
// ... other methods ...
}
- Add canAttack variable as an additional condition for triggering AttackBehavior()
private void Update()
{
if (health.IsDead())
{
return;
}
if (InAttackRangeOfPlayer() && fighter.CanAttack(player) && canAttack)
{
AttackBehavior();
}
else if (timeSinceLastSawPlayer < suspicionTime)
{
SuspicionBehavior();
}
else
{
PatrolBehavior();
}
UpdateTimers();
}
- Update the Cinematic Control Remover script:
4a) Create an array of GameObjects related to the enemy
GameObject player;
GameObject enemies; //array of enemeies
4b) Inititialize the eneimes list in the start method:
private void Start ()
{
GetComponent().played += DisableControl;
GetComponent().stopped += EnableControl;
player = GameObject.FindWithTag(“Player”);
enemies = GameObject.FindGameObjectsWithTag(“Enemy”); // Initialize enemies with “Enemy” tag
}
4c) Update the Enable/Disable Control Methods created in this video and the prior video. Loop through each enemy in enemies array → set their newly created canAttack propery to false.
void DisableControl(PlayableDirector director)
{
foreach (GameObject enemy in enemies)
{
AIController aiController = enemy.GetComponent();
if (aiController != null)
{
aiController.canAttack = false; // Disable attacks only
}
}
player.GetComponent().CancelCurrentAction();
player.GetComponent().enabled = false;
}
void EnableControl(PlayableDirector director)
{
foreach (GameObject enemy in enemies)
{
AIController aiController = enemy.GetComponent();
if (aiController != null)
{
aiController.canAttack = true;
}
}
player.GetComponent().enabled = true;
}
Applying these changes, the game play becomes more dramatic because as soon as you come out of the cinematic sequence, you see one one, or in my case, several guards charging towards you, which creates a sense of urgency. Also, I further down the line I plan to implement an invisibility cloak/shield of sorts, and I would like to use this trigger to disable guard attack behavior as well, so all this will help there as well.
Just thought I would share and show off my learning a little … lol …