Hello again. OK so… there are a few things that I am struggling to fix:
-
The enemy won’t patrol for some reason. I made a copy off my working enemy, but this one is stubborn and just won’t patrol. Nothing changed, but I can’t get a patrol path from the scene itself on his prefab (I’m guessing that’s the problem), and unsurprisingly, he won’t move… Is there any other steps I missed out on to fix this? (and when he respawns, he’s… standing airborne to say the least - he’s basically not taking any type of gravity). He won’t attack, patrol, get impacted on hits, or play any death animations… Something is completely off here
-
It’s an Out-of-context problem. I’ll leave it at the very end (but I do need your help addressing it)
-
For now, it’s perfectly fine that the arrow won’t hit anything beyond a few centimeters, right?
-
We shall address the experience gain in the future as well, right?
I followed the tutorial exactly as is, but these 4 issues still exist… I’m guessing at least 1,3 and 4 (I will address 2 later. It’s a shame to have a brilliant system like a quiver and leave it out to be honest) will be addressed soon, right?
I also have to mention that although the lecture did not mention adding the ‘Shoot()’ event (or at least I didn’t catch it), I placed it on the animation myself
- I had a Quiver System that I introduced in the past, and I was trying to integrate it into my game. Frankly speaking, I have a bit of a funny approach to this one, and I’d like some help on it
So, to begin with, I managed to get my player to lose a single arrow per hit, which means ultimately he will run out of arrows, using my own Quiver system, as follows (this is what my ‘Shoot()’ function looks like after implementing it):
void Shoot() {
// In very simple terms, this function is the 'Hit()' function for
// Ranged (Projectile) Weapons, to be called in 'Projectile.cs' (for simplicity in naming's sake)
// Hit();
// RPG to Third Person Conversion change:
if (!currentWeaponConfig.HasProjectile()) return;
if (TryGetComponent(out ITargetProvider targetProvider))
{
float damage = GetDamage();
GameObject targetObject = targetProvider.GetTarget();
if (targetObject != null)
{
// use the 'LaunchProjectile' function with 5 arguments (as we do have a target)
currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, targetObject.GetComponent<Health>(), gameObject, damage);
}
else
{
// use the 'LaunchProjectile' function with 4 arguments (as we don't have a target)
currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, gameObject, damage);
}
// (Arrow Deduction here) If you have enough ammo, fire and use the ammo
if (currentWeaponConfig.GetAmmunitionItem())
{
GetComponent<Quiver>().SpendAmmo(1);
}
}
}
However, I also wanted him to be able to take the bow off his hands (like I did before) if you’re out of ammo, and you attempt to attack something or someone, so I introduced these 2 functions:
void CheckAmmoQuantity()
{
// If the weapon demands ammo (ranged weapon), but you don't have enough ammo, unequip the weapon and go fight with your hands
if (currentWeaponConfig.GetAmmunitionItem() && !GetComponent<Quiver>().HasSufficientAmmunition(currentWeaponConfig.GetAmmunitionItem()))
{
UnequipRangedWeapon();
}
}
the function above is assigned as an animation event, played only at the start of the bow-firing animation
and this:
private void UnequipRangedWeapon()
{
if (!inventory.HasSpaceFor(currentWeaponConfig)) return;
GetComponent<Fighter>().GetComponent<Inventory>().AddToFirstEmptySlot(currentWeaponConfig, 1, true);
GetComponent<Fighter>().GetComponent<Equipment>().RemoveItem(EquipLocation.Weapon);
}
This function unwields the ranged weapon basically
However, the last step I want to do is to avoid playing the ‘Bow’ animation entirely if the player doesn’t have any ammo on him, and the ‘CheckAmmoQuantity()’ function turns out as true (no clue why I didn’t make it a boolean tbh…), and instead punch whoever is ahead of him (you’re out of ammo, and you have nothing in your hand by default)
[UNNECESSARY, BUT YOU MIGHT FIND THIS HELPFUL]
To help out though, I also found this function I once created, but I don’t recall what it does:
bool CheckForProjectileAndSufficientAmmo() {
// Step 1: If the weapon doesn't have a projectile (swords or basically any melee weapons), you're good
// Step 2: If the weapon doesn't use Ammunition (maybe an infinity staff or some sort of infinite projectile), you're good
// Step 3: If you have enough ammo for the right weapon you're holding, you're good
// Step 4: If you have ammo, but for the wrong weapon, then unequip your weapon and rush to hand-to-hand combat (you're NOT good)
// Step 1:
if (!currentWeaponConfig.HasProjectile()) {
return true;
}
// Step 2:
if (currentWeaponConfig.GetAmmunitionItem() == null) {
return true;
}
// Step 3:
if (GetComponent<Quiver>().HasSufficientAmmunition(currentWeaponConfig.GetAmmunitionItem())) {
return true;
}
// Step 4:
if (currentWeaponConfig.GetAmmunitionItem() && !GetComponent<Quiver>().HasSufficientAmmunition(currentWeaponConfig.GetAmmunitionItem())) {
// If you want to keep pointing at your player without attacking them because of insufficient/wrong ammo, delete 'UnequipRangedWeapon()' below:
UnequipRangedWeapon();
return false;
}
// Anything else is just false:
return false;
}