Thursday
Currently, the player can only attack a previously defined enemy. This is not something that I’d like as it means the player has no choice over who they attack and also doesn’t allow for attacking any other enemies after it has been killed.
To fix this, I wanted to add a lock on system that the player can cycle through to decide who they attack, and only deal damage to the enemy the player is locked on to.
With the help from James, we started by creating a new script called PlayerLockon. This acts as the main script to calculate which enemy the player is attacking. We created 2 new variables, a GameObject called target, and a List called Enemies.
public GameObject target;
public List<GameObject> enemies;
In the Update() method, I first debug the number of enemies that the player is range and then run the LockOn() method.
void LockOn()
{
MakeListOfEnemies();
if(enemies.Count > 0)
{
target = enemies[counter];
}
}
The LockOn() method runs a new method called MakeListOfEnemies().
void MakeListOfEnemies()
{
foreach(GameObject e in enemies)
{
if(!e)
{
enemies.Remove(e);
}
}
Collider[] everything = Physics.OverlapSphere(transform.position, attackScript.combatIdleRadius);
foreach(Collider c in everything)
{
if(c.gameObject.tag == "Enemy" && !enemies.Contains(c.gameObject))
{
enemies.Add(c.gameObject);
}
}
}
This method first runs a loop for each GameObject in the enemies list. As the method is run every frame, a check is made to make sure there are no duplicated enemies, if so, they are removed.
A collider is also made that can detect the enemies inside. For each object inside the collider, a check is made to detect if they are enemies or just static objects. If the tag is “Enemy”, then they are added to the list.
Back in the Update() method, this is where the actual player locks on to the target.
if (Input.GetKeyDown("l"))
{
if(counter < enemies.Count - 1)
{
counter += 1;
look = 1;
}
else
{
counter = 0;
}
}
If the ‘L’ key is pressed, a check is made to see if the counter is less than the number of enemies in the list minus 1. If so, the counter is incremented by 1 and the look variable is set to 1, else the counter variable is set to 0/
foreach (GameObject e in enemies)
{
if (target == e)
{
e.transform.GetChild(2).GetChild(2).GetComponent<Image>().enabled = true;
}
else
{
e.transform.GetChild(2).GetChild(2).GetComponent<Image>().enabled = false;
}
}
A new foreach loop is made for each GameObject in the enemies list. If the index of the loop is the same as the target, an image component is enabled, identifying the target the player can attack. If this isnt’ the case, the image is disabled.
An adjustment is needed to be made in the PlayerAttack script. I need to change the enemy variable to be the target calculated instead of a predetermined enemy. To do this, I made reference to the PlayerLockon script in the attack script.
PlayerLockon lockOnScript;
void Start()
{
lockOnScript = GetComponent<PlayerLockon>();
}
Finally, I need to keep this adjustment updated so in the Update() method of the attack script, I added a few lines of code.
enemy = lockOnScript.target;
enemyController = enemy.GetComponent<EnemyController>();
This script works fine when the player attacks the enemy they are locked onto however, it would be better if the player can break away from combat and start attacking a new enemy. They can do this by cycling through each enemy in the list, however a more efficient and player friendly way would be to allow the player to approach the new enemy and assign that one to be the target.
Friday Meeting – Combat
After a team meeting held last Friday, we decided to rework the combat mechanics a bit. Currently, I am trying to code different combat styles in one and it’s causing errors between scripts so a more streamlined solution needed to be figured out.
We worked out that the player can only use combos when locked on to a target. We assigned the Left and Right bumpers to be used for the lock-on. LB to toggle the lock-on on or off and RB to cycle between enemies when locked-on. When the the player is locked-on, enemies cannot attack them however will circle around the player, looking ready to prepare for an attack. This will hopefully trick the player into thinking there is some urgency to their attacks.
We decided that when locked-on, the player can initiate a combo. We gave the player 2 combos; a perfect combo, and an imperfect combo. The perfect combo insta-kills the enemy and gives the player 2x the karma they would have gotten. In order to get a perfect combo, the player needs to input the combo buttons with a 1 sec rhythm. The imperfect combo uses the same buttons but when not done in time, the damage is multiplied but won’t insta-kill the enemy.
The combo follows this pattern:
B, A, LT-B, LT-A, X
When the player completes this sequence, they press Y to complete the combo.
Friday Meeting – Camera Orbit
We worked out that the camera needs to focus on the locked-on enemy and follow the player as they are locked-on.
This clip best describes the camera/combat we are aiming for. (Start at 4:15)
Leave a comment