Antivirus Reference: Requirements
Antivirus Reference: Requirements
Table of Contents
Requirements............................................................................................................................................. 1
Behavior..................................................................................................................................................... 1
Overview............................................................................................................................................... 1
States..................................................................................................................................................... 1
Summary...........................................................................................................................................2
State Definitions............................................................................................................................... 2
Components............................................................................................................................................... 2
Child Objects..............................................................................................................................................3
Requirements
The following is a list of objects and references needed for the proper behavior of the Antivirus' three
interactions with the game world (movement, tracking, firing):
• Movement: Game Objects with colliders tagged “Edge” or “Wall”.
• Tracking: a reference to the Player in the Antivirus AVBrain script component.
• Firing: a reference to the Player in the Antivirus AVBrain script component, a Child
GameObject with the script Turret Behavior as a component, and a reference to a projectile
prefab in the Child Object's Turret Behavior script component.
Behavior
Overview
The Antivirus' behavior is defined in the AVBrain script component by a finite state machine (FSM).
This FSM consists of a set of transitions, and a set of states. Each state contain a definition for the
methods Reason(GameObject, GameObject), Act(GameObject, GameObject), and OnCollide() that are
called each FixedUpdate. These methods do the following:
• Reason(GameObject player, GameObject npc): determine if the conditions for making a
transition to another state have been met. If multiple transitions have been defined for that state,
check which ones, if any, should be made, and transition to the new state.
• Act(GameObject player, GameObject npc): defines the actions of the GameObject while they
are in a given state.
• OnCollide(): defines any special action that should be taken by the GameObject during a
collision. OnCollide() is called in OnCollisionEnter().
States
Summary
While there is no player in sight, the Antivirus (AV) patrols a small area, pacing back and forth.
When a player enters the AV's line of sight, the AV moves towards the player, but stops a small distance
away from the player. When it is near enough to the player, the AV will open fire, spacing each shot
with a small cool down. If the player moves a sufficient distance away, the AV will stop shooting and
give chase to the player; in the case where the player dies, the AV goes back to patrolling. During the
chase, if the player moves a sufficient distance away, or the AV is unable to keep chasing the player, the
AV will give up and go back to it's original patrol area; otherwise, if the AV manages to catch up, it will
start shooting again until the player is not a valid target (i.e. the player moves away, or dies).
State Definitions
The Antivirus' behavior is defined by three states (Patrol, Attack, Chase)
• Patrol
◦ Reason(): if the player is within the FieldOfViewAngle, transition to the Attack state.
◦ Act(): from a starting position StartPosition choose a random direction and move a distance
PatrolRange in that direction, then go back to StartPosition and move PatrolRange in the
other direction.
◦ OnCollide(): if the collision gameObject's tag is either “Wall” or “Edge” go back to the start
position and move in the other direction.
• Attack
◦ Reason(): if the Player is SightRange + 5f away from the Antivirus, the Player is getting
away; transition to the Chase state. Else if the player is dead, transition to the Patrol state.
◦ Act(): if the Player is further away from the Antivirus' fire range move until the Player is in
range. When the Player is within TargetRange and FieldOfViewAngle, and can be seen (via
Raycast) call the Turret Child Object's Turret Behavior script with the normalized direction
of the Raycast hit.
◦ OnCollide(): there are no special actions to be taken during a collision.
• Chase
◦ Reason(): if the player is SightRange + 7f away from the Antivirus, the Antivirus lost the
player; transition to the Patrol state.
◦ Act(): if the Player is within the FieldOfViewAngle, and can be seen (via Raycast), close in
on the Player.
◦ OnCollide(): there are no special actions to be taken during a collision.
Components
• Transform
• Box Collider
• Rigidbody
• AVBrain (script):
◦ Public variables:
▪ Field of View Angle (float): used to determine where the Player needs to be to be seen
by the Antivirus. Used by the Patrol, Attack, and Chase states.
▪ Sight Range (float): determines how far the Antivirus has to be from the player to act,
and used to check if the Player is getting away. Used by the Patrol, Attack, and Chase
states.
▪ Target Range (float): determines how close the Antivirus needs to be to the player
before it can shoot. Used by the Attack state.
▪ Patrol Speed (float): determines how fast the Antivirus moves in the Patrol State. Used
by the Patrol State.
▪ Patrol Range (float): determines how far the Antivirus will go in a direction before
returning to the Start Position. Used by the Patrol State.
▪ Move Speed (float): determines how fast the Antivirus will close in on the Player. Used
by the Attack and Chase states.
▪ Start Position (Vector3): determines the center of the Antivirus' patrol route. Used by
the Patrol state.
▪ Player (GameObject): A reference to the Player GameObject. Used by the AVBrain
Finite State Machine's states to calculate actions and transition conditions. Used by the
Patrol, Attack, and Chase states.
Child Objects
• Turret: contains the actual logic for shooting.
◦ Components
▪ Transform
▪ Box Collider
▪ TurretBehavior (script): once the AVBrain script has worked out if the Antivirus can
shoot, and where to shoot, it calls TurretBehavior.Fire(Vector3 direction).
• Public variables:
◦ Fire Prepared Timing (float): determines how long the cool down between
shots last.
◦ Projectile (GameObject): a reference to a Projectile prefab, used by Fire() to
instantiate a bullet.
◦ Projectile Speed (float): determines how fast the Projectile will move once
instantiated.