am I the only one who NEVER had an ‘OnWeaponChanged’ event before reading the new Projectile tutorial…?
Edit: A few more questions (five) for now at least (I’m not sure if the rest were just me adding stuff, or they were in there for a while yet…):
[SOLVED the first one]
-
"where did you get ‘sphereCollider’ in the ‘Targeter.cs’ from? (Edit: I created a variable and then cached it in awake, when I noticed that the targeter script and (I’m guessing here…) the sphere we are referring to are on the same GameObject)
-
Do we replace the current ‘GetAttackingRange()’:
public float GetAttackingRange()
{
return currentWeaponConfig.GetRange(); // replacement for third person transition below
}
with this one?
public float GetAttackingRange()
{
return currentWeaponConfig.GetTargetRange();
}
[EDIT: I replaced them]
3. In your cleaned up version of ‘Fighter.cs’, I keep seeing nearly everywhere the use of ‘GetRange()’ instead of ‘GetTargetRange()’… is that on purpose, or should I replace them? Because I did replace them… (In fact, I completely deleted any reference to ‘weaponRange’ now and replaced all the references to it with ‘targetRange’ now… Not sure if that was the right or wrong step, but that seemed like the natural evolution step)
[GAVE IT A GO]
4. For some reason, before I get into getting the enemy to respond to my attacks, I tried to go ahead and fire arrows at the enemy from the player, but unless he’s extremely close (still), no damage will be done to the enemy. I checked the ‘targetRange’ effect, and it worked to get the range to be large (however swinging a sword from 10 meters away will be effectless for obvious reasons), and I also checked the sphere radius of the targeter, and it did expand. However, I still can’t hit an enemy from a large distance for some reason, even with a large target Range… How do I fix this? (There’s also a few errors coming up, but these are from personal experimentation. They have nothing to do with this problem)
Edit: I don’t know how this was missed out from the tutorial, but to strike an enemy from a distance, and he’s in the range of the weapon, here’s what I tried doing. I placed this in ‘Shoot()’:
// If he's in range, hit him:
if (Vector3.Distance(transform.position, targetObject.transform.position) < currentWeaponConfig.GetTargetRange())
{
// ignore the 'GetSkill()' at the end, that's custom code I created for myself
targetObject.GetComponent<Health>().TakeDamage(gameObject, damage, currentWeaponConfig.GetSkill());
TryApplyHitForce(targetObject.GetComponent<Collider>(), transform.position);
}
so now my ‘Shoot()’ looks like this:
// Called on the melee animation event lines:
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 changes are what the rest of this function is all about:
if (!currentWeaponConfig.HasProjectile()) return;
if (TryGetComponent(out ITargetProvider targetProvider))
{
float damage = GetDamage();
GameObject targetObject = targetProvider.GetTarget();
if (targetObject != null)
{
// (TEST) inject code here to gain experience if targetObject is dead (after the projectiles are fully fixed):
// use the 'LaunchProjectile' function with 5 arguments (as we do have a target)
currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, targetObject.GetComponent<Health>(), gameObject, damage);
// If he's in range, hit him:
if (Vector3.Distance(transform.position, targetObject.transform.position) < currentWeaponConfig.GetTargetRange())
{
targetObject.GetComponent<Health>().TakeDamage(gameObject, damage, currentWeaponConfig.GetSkill());
TryApplyHitForce(targetObject.GetComponent<Collider>(), transform.position);
}
}
else
{
// use the 'LaunchProjectile' function with 4 arguments (as we don't have a target)
currentWeaponConfig.LaunchProjectile(rightHandTransform, leftHandTransform, gameObject, damage);
}
// If you have enough ammo, fire and use the ammo
if (currentWeaponConfig.GetAmmunitionItem())
{
GetComponent<Quiver>().SpendAmmo(1);
}
}
}
Not sure if that’s right or wrong, but for now it seems to be working just fine (apart from no applied force properly done).
However, I must say that I would’ve preferred a thousand times if a projectile acted like a real projectile. In other words, fire the arrow straight ahead (if it’s a non-homing arrow), and if it hits something, damage that thing, instead of just damaging anything in your range… If it misses, it missed. That would make for a fun and realistic ranged interaction, instead of just, you know… always getting the shot. What fun is that?
-
Are these projectiles going in a straight line, or do they just instantiate a particle system on the target (which is kind of what I’m seeing right now )? It would be nice if we fire a projectile with the idea of “if it hits, it hits. If it misses, it misses…”, and maybe even a trail for that
-
I went ahead and added the enemy aggregation, and it worked marvelously… but I noticed something, because I have an AggroGroup involved in the mix as well: If you strike one guy, and you’re not in his range, he will chase you down. However, the aggroGroup does NOT care if you’re not in their range, and they’ll be hostile pretty much forever, but won’t act on it until you get into their chase range. Any chance we can get them to want to hunt you down as well until the cooldownTimer is over, regardless of their individual chase range? So when the timer is over (for each individual enemy), everyone in the aggroGroup mentioned in this lecture cools down as well, unless the player attacked them
In simple terms, when you aggregate one, and he’s part of an AggroGroup, aggregate everyone else as well in the AggroGroup, and get them to chase you, regardless of your range, until the initial cooldown timer is done (so initially, when one of the group is hit at first, everyone’s aggro cooldown timer works, and then unless the player attacks them individually, they no longer care and walk away, once that initial timer is done).
I also have a bug that my enemy for some reason actually damages my player twice the damage the UI shows up, but I’ll address that once these 5 questions are done (I tried deleting the hit events, that didn’t work. I tried erasing the damage modifier multiplication line (and checking them on the attacks’ inspector, but they were set to 1. I halved them, and still… the damage dealt was double what the damage text spawner showed on the screen). That didn’t work either… I think ‘OnTakenHit’ is being called twice somewhere for the enemies. The player, even more surprisingly, doesn’t have that problem). After a bit more analysis, I realized it’s like the enemy is calling ‘TryHit’ twice, but the damage spawner catches it once. I checked the event relays on the animation, seems like it’s only called once…
Sorry for the ton of questions…