Creating Smart Enemies
Shooting when the Player is being behind it or Shooting at Power Ups
Objective: Create an enemy type that knows when it’s behind the player, and fires a weapon backwards.
I Created a new Behavior that inherits from Weapon. I use Raycasting to detect if the player is behind the weapon. If it is I fire the weapon and start the rear firing laser cooldown.
Next I create a Smart Enemy prefab from the Enemy prefab.
I edit the Smart Enemies weapon. I remove the Weapon Component and add I added the Enemy Smart Weapon. I set the regular laser options up.
I then created a Laser prefab to fire Backwards.
I then set the seek parameters and added the rear firing laser.
I then play tested to make sure the new enemy works.
Shooting at Power Ups
Objective: If a pickup is in front of an enemy, the enemy will fire its weapon at the pickup to destroy it before the player can get it.
First I create a laser that can destroy a power up. I had to add 2 new Tags for the power up and the destroyer
Next I added the need Tags to the Power ups.
I Modified the Smart Enemy to use the power up destroyer as a secondary weapon. I also moved the seeking detecting to in front of the enemy.
I made the new Enemy a Prefab Variant and add several power ups to the scene.
Everything is set but things are not working. This is because the power ups and the laser do not have ridged bodies attached, the requirment for a collision to happen is that one of them need a ridged body.
I add ridged bodies to the power ups.
Now all that needs to be is to add a new Behavior that reacts to power ups the way that I want. I want the new laser type to be able to destroy the power ups without the Power up Collected Game Event being fired, Damageable will fire what ever event that is listed no mater what destroyed it. I also don’t need the lives and shield stuff so I just made a stripped down version of the Damageable for the PowerUp.
Next I removed the Damageable from all of the power up prefabs and added the PowerUp to them. I then set all the parameters. I also made it so the Player can shoot the Shield Power Down and Destroy it.
The new Enemy now destroys the power ups.