Starting with Beta version 1.5, we have implemented grenade attacks. A bot will use grenades, if he has any, during his ranged attack phase.
Our A.I. kit comes with a basic implementation of grenade attack decisions. The grenade FSMs also have Area of Effect (AOE) damage built-in.
BASIC IMPLEMENTATION: We focused more on performance, so we reduced the number of Vector3 calculations per grenade phase. So instead of having the bot calculate optimal grenade positioning, we have it simply toss the grenade at a force. This means a lot of times the bot’s grenade will not land at the enemy’s feet. The bot also determines randomly whether to toss a grenade or fire his gun.
ADVANCED IMPLEMENTATION: In the future, we will have an advanced add-on for purchase, where the bot will initiate a ton of Vector3 calculations to determine the optimal force/angle/height to throw the grenade. This, however, will come at a performance cost. Additionally, the bot will no longer use random grenade tosses, but only toss the grenade given a certain number of enemies in the area, to maximize area of effect.
STEP 1: In the Attack FSM: Enable grenade attacks on the bot. Simply set “charSTAT_GrenadeChance” to anything above 0. Likewise, set it to 0 (zero) to turn off grenade attacks. The following parameters pertain to the grenade attack for the bot.
- GrenadeChance – the chance, out of 100, of the bot throwing a grenade during a ranged attack. So each time the bot is about to shoot, he will calculate a random grenade chance…if the number hits, he will throw a grenade instead of shooting his gun. So, setting it to 50 means there is a 50/50 chance the bot will throw a grenade.
- FireRange – the grenade attacks shares the fire range with the gun attacks. If an enemy falls into this distance, the bot will execute a ranged attack.
- GrenadeForce – The forward force (physics engine) to throw the grenade
- GrenadeUpForce – The upward force (physics engine) to throw the grenade
- GrenadeRecoveryTime – after the bot throws a grenade, the time, in seconds, to wait before taking another action. Example: If you have a long grenade throw animation, set this to a longer time.
STEP 2: Drag a grenade prefab into the bot’s slot. For this demo, just use the Grenade Template.
STEP 3: Edit grenade damage and explosion effect. Grenade damage is set inside the Grenade prefab itself, not the bot. So click the Grenade prefab and edit the FSM variables:
- ExplosionForce – this is for special effect only. It creates an amount of force, by RADIUS, around the explosion. It uses the physics engine to create a blast zone (see the Grenade demo scene. Notice the boxes flying everywhere?). Does not affect damage.
- ExplosionRadius – this is Area of Effect (AOE) damage. All enemy (or friendly) bots within this radius will be damaged.
STEP 4 (optional): Create your own custom grenade or use a custom grenade model. It’s easy to make your own custom grenade or model. Drag the GrenateTemplate into your scene. Open up the hierarchy and replace the child model with your own raw model. Then drag the new grenade prefab into your Assets folder to create a usable prefab.