Catalogue

Monday, June 27, 2016

Scripting 2: Script: Shooter_AI

Shooter_AI is a script used by enemies that shoot projectiles.


This is an overview of the Shooter_AI Script.

This script contains 13 public variables and 9 private variables. Every public variable is used to customize the projectile being shot.


VOID Start()  Only used to set the pooler boolean.
bulletshot: The array of projectiles being shot, customizable.
pooler: If true, then all projectiles are created from the start, if false then projectiles are created when they're shot.
if the length of the bulletShot array is larger than 1 projectile, pooler is set to true and RefChecker() is called. Otherwise pooler is set to false.


VOID Update()  Only used to control knockback
Sets the motion of the enemy. Like the HPscript, Shooter_AI has its own special movements. These movements are used only to affect the enemy's knockback after shooting a bullet.
Lerps hspeed and vspeed to 0 by 0.2f;
transform.Translate(hspeed/10,vspeed/10,0);

public VOID ProjectChoose()  This is the function called by other scripts.
if pooling:
  • Checks each projectile saved in the bulletshot array.
  • The fires the first inactive projectile found with StartCoroutine("ProjectileToss", bulletshot[tC];
  • If the checked projectile is active, tC+=1, and the next projectile is checked.
if not pooling:
  • objReffed = Instantiate(bulletshot[0]);
  • The fired projectile's function are reset through the ProjRefSet function.
  • Then the projectile is fired with StartCoroutine("ProjectileToss",objReffed);
IENUMERATOR ProjectileToss(GameObject tRef) Fires the projectile
  • First checks the enemy HP. If HP is lower than 0, all coroutines end immediately.
  • At this point, the object is disabled and enabled to ensure it gets reset.
  • The projectile's position is first set to the object firing it, with a displacement created by the Vector 2 bullDistance.
  • The knockback is set based on shootStrength; Vector2
  • The projectile's hspeed and vspeed are set based on bulletspeed; Vector3
  • The projectile's gravity is set based on bulletslow; Vector3
  • The damage is set based on bulletDamage; Integer
  • The element is set based on bulletElement; String
VOID RefChecker() Only used for pooling, creates all the pooled projectiles.
  • Each prefab in bulletShot is instantiated;
  • Each prefab in the bulletShot array is replaced with the newly created gameObject;
  • ProjRefSet() is called for each projectile;
  • Each projectile is now deactivated.
VOID  ProjRefSet(GameObject bulRef) set the projectile variables.
  • startTime = How long the bullet will remain active before despawning.
  • initialSize = Original size of the bullet.
  • sizing = Active size of the bullet.
  • element = Physical traits of the bullet, given through a string.
  • diesOnHit = whether or not the bullet will be destroyed upon collision.
  • homePoint = whether or not the bullet will home in on the player.
  • After all the variables are set, the bullet is parented to the "Projectile_List" gameObject for the sake of organization. This gameObject is located within the Scene_Prefab object present in all levels in the game.

No comments:

Post a Comment