![]() |
Eye of the Nile Docs
Everything you need to know to get started!
|
Basic functionality for any entities that are hostile towards other entities. This script is abstract so it must be inherited by another script to be used. Every script inheriting from this must override ActivateAttack().
Documentation updated 11/9/2024
Public Member Functions | |
void | ChangeSpeed (float speedChange) |
Speeds up or slows down the entity's movement speed. A negative value for speedChange will slow down the entity. | |
void | ChangeSpeed (float speedChange, float duration) |
Temporarily speeds up or slows down the entity's movement speed. A negative value for speedChange will slow down the entity. | |
void | DestroyOnDeath () |
Can be optionaly run by ObjectHealth.onDeath. | |
Protected Member Functions | |
void | ActivateAttack () |
Triggered by an event in the attack animation (or you can override TriggerAttack() if there is not attack animation). This function muse be overridden by any inheriting class. | |
virtual void | TriggerAttack () |
Triggers the entity's attack. This can be done through triggering an animation, spawning a projectile, or another method. By default, an "IsAttacking" animation is triggered. | |
virtual void | PatrolState () |
When the entity hasn't detected any enemies... | |
virtual void | ChaseState () |
If the entity has detected an enemy... | |
virtual void | CloseAttackState () |
If the entity is close enough to an enemy to attack... | |
Protected Attributes | |
ObjectHealth | objectHealth |
Reference to the object responsible for managing the player's health. | |
Transform | attackPoint |
Reference to the entity's attack point. It's a point in space that's a child of the entity, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it. | |
int | attackDamage = 30 |
Amount of damage the entity's attack will deal. | |
float | attackCooldown = 0.8f |
The amount of time between attacks. | |
float | cooldownEndTime = 0f |
Amount of time until cooldown is over. Set to the current time + attackCooldown when the attack is triggered. | |
LayerMask | enemyLayers |
Objects on these layers will be considered an enemy of this entity, and if detected, this entity will seek to attack. An object can be assigned to a layer in the Unity Editor from a drop down menu in the top right. | |
PatrolZone | patrolZone |
A patrol zone is an object that has two points the entity will walk between if it does not detect an enemy. | |
float | horizontalDirection = 0f |
Horizontal direction the entity is traveling in. | |
float | detectionRange = 6f |
How far away the entity will detect an enemy from and start chasing. | |
float | activateAttackRange = 3f |
How close the entity must be to an enemy to attack it. | |
float | entityCenter = 1.4f |
bool | hostileDetected = false |
True if the entity has detected an enemy. | |
bool | hostileInCloseRange = false |
True if the entity is close enough to an enemy to attack it. | |
Rigidbody2D | rb |
Reference to the entity's rigidbody. | |
float | moveVelocity = 6.0f |
How fast the entity should move. | |
float | speedModifier = 0f |
The precent of moveVelocity the entity should move at. Used for slowing the entity down. | |
float | linearDrag = 1.0f |
Amount of drag to apply to the rigidbody. | |
float | groundedRaycastLength = 1.8f |
GroundDetector | groundDetector |
Reference to the entity's GroundDetector. | |
bool | groundNeeded = true |
Can be set to false to let the entity walk even when it is not on the ground. | |
bool | canWalk = true |
Used for disabling entity movement. | |
Animator | animator |
Reference to the entity's animator. | |
Properties | |
EntityState | EState = EntityState.Patrol [get, protected set] |
Current state the entity is in. | |
Private Member Functions | |
void | Start () |
Apply linear drag to the rigidbody. | |
void | Update () |
Activate the logic for the current state for this frame, based on EState. | |
void | OnDrawGizmosSelected () |
Displays radiuses of the detection and attack circles in the Unity Editor, specifically the scene view. This allows developers to see how far away an entity can see an enemy and how far way they will attack the enemy. | |
void | Awake () |
Set references to rigidbody, animator, object health, and GroundDetector. | |
IEnumerator | ChangeSpeedClock (float speedChange, float duration) |
Clock for ChangeSpeed(). See ChangeSpeed() for details. | |
|
abstractprotected |
Triggered by an event in the attack animation (or you can override TriggerAttack() if there is not attack animation). This function muse be overridden by any inheriting class.
|
private |
Set references to rigidbody, animator, object health, and GroundDetector.
void BaseEntityController.ChangeSpeed | ( | float | speedChange | ) |
Speeds up or slows down the entity's movement speed. A negative value for speedChange will slow down the entity.
speedChange | The amount that will be added to speedModifier, which will be added to moveVelocity. |
void BaseEntityController.ChangeSpeed | ( | float | speedChange, |
float | duration ) |
Temporarily speeds up or slows down the entity's movement speed. A negative value for speedChange will slow down the entity.
speedChange | The amount that will be added to speedModifier, which will be added to moveVelocity. |
duration | The amount of time, in seconds, the speed change will last for. |
|
private |
Clock for ChangeSpeed(). See ChangeSpeed() for details.
|
protectedvirtual |
If the entity has detected an enemy...
Reimplemented in RockGolemController.
|
protectedvirtual |
If the entity is close enough to an enemy to attack...
Reimplemented in RangedEntityController.
void BaseEntityController.DestroyOnDeath | ( | ) |
Can be optionaly run by ObjectHealth.onDeath.
|
private |
Displays radiuses of the detection and attack circles in the Unity Editor, specifically the scene view. This allows developers to see how far away an entity can see an enemy and how far way they will attack the enemy.
|
protectedvirtual |
When the entity hasn't detected any enemies...
|
private |
Apply linear drag to the rigidbody.
|
protectedvirtual |
Triggers the entity's attack. This can be done through triggering an animation, spawning a projectile, or another method. By default, an "IsAttacking" animation is triggered.
Reimplemented in MeleeEntityController, and RangedEntityController.
|
private |
Activate the logic for the current state for this frame, based on EState.
|
protected |
How close the entity must be to an enemy to attack it.
|
protected |
Reference to the entity's animator.
|
protected |
The amount of time between attacks.
|
protected |
Amount of damage the entity's attack will deal.
|
protected |
Reference to the entity's attack point. It's a point in space that's a child of the entity, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it.
|
protected |
Used for disabling entity movement.
|
protected |
Amount of time until cooldown is over. Set to the current time + attackCooldown when the attack is triggered.
|
protected |
How far away the entity will detect an enemy from and start chasing.
|
protected |
Objects on these layers will be considered an enemy of this entity, and if detected, this entity will seek to attack. An object can be assigned to a layer in the Unity Editor from a drop down menu in the top right.
|
protected |
|
protected |
Reference to the entity's GroundDetector.
|
protected |
|
protected |
Can be set to false to let the entity walk even when it is not on the ground.
|
protected |
Horizontal direction the entity is traveling in.
|
protected |
True if the entity has detected an enemy.
|
protected |
True if the entity is close enough to an enemy to attack it.
|
protected |
Amount of drag to apply to the rigidbody.
|
protected |
How fast the entity should move.
|
protected |
Reference to the object responsible for managing the player's health.
|
protected |
A patrol zone is an object that has two points the entity will walk between if it does not detect an enemy.
|
protected |
Reference to the entity's rigidbody.
|
protected |
The precent of moveVelocity the entity should move at. Used for slowing the entity down.
|
getprotected set |
Current state the entity is in.