Ranged attacks are simple and fun to set up. Some combinations can build some pretty cool effects! Please see the included demo scene, “Weapon Switching” to see how you can tweak the Attack FSM variables to create different types of weapons. All bots come with ranged attacks, both gunfire and grenade throwing.
In a typical fight scenario, the bot’s action process goes like this:
[Bot detects enemy within shoot range] -> [Use grenades or use gun?] -> [Execute attack with either grenade or gun] –> [If using gun, fire burst shot] -> [Wait for next fire time]
STEP 1: First, enable Ranged attacks on the bot. In the Attack FSM, set this to true:
STEP 2: Drag a bullet type into the bot’s weapon slot. If you noticed, you can use any bullet model, from rockets to shotgun shells, to arrows and rocks! However, you have to set up the bullet model with 2 required FSMs before adding (see the Bullet Tutorial). For this tutorial, we will keep it simple and use our pre-configured demo bullets.
STEP 3: Now that you have the model, you now set up how the bullet is fired. The following parameters all pertain to the projectile ranged attack system (for grenades, see the grenade tutorial). Feel free to tweak the numbers to get some cool results!
A few tips:
- ammoRemaining – current ammo remaining in the clip. When the clip is used up, the bot will reload.
- BulletUseRaycast – set to true if you want to use hitscan damage instead of collider damage. Hitscan damage instantly impacts the target, like a sniper rifle.
- currentBulletSpd – this is the force (uses Unity physics engine) exerted on the bullet. This is affected by gravity and all Unity’s physics properties. At very long distances, the bullet should drop, given enough gravity.
- FireRange – this is the maximum distance the bot will start using ranged attacks. If this number is much smaller than the sightRange (Awareness FSM), the bot will chase down the target.
- MuzzleFlash – this is simply a particle or explosion prefab that is spawned at the tip of the bot’s gun barrel.
- GunBurstSize – the burst per trigger pull. A burst of 3 means each trigger pull will create 3 quick shots. This is similar to the Battle Rifle effect in the Halo games.
- ShootWaitSec – seconds to wait before another trigger pull