Forum begins after the advertisement:
[Part 15] Whip Weapon not visible during attack
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 15] Whip Weapon not visible during attack
- This topic has 25 replies, 2 voices, and was last updated 4 months, 1 week ago by Terence.
-
AuthorPosts
-
July 11, 2024 at 7:49 pm #15249::
Do you mean the pivot in each sprite?
If so, the sprites have different pivots because I though it looked strange otherwise.Edit: I just changed the pivots in the sliced spritesheet so they´re all “center” , but that doesnt change the fact that the whip cant keep pace with the player
July 11, 2024 at 7:59 pm #15250::I also get these errors everytime the weapon/player is in the vicinity of an enemy:
July 11, 2024 at 8:02 pm #15251July 11, 2024 at 8:25 pm #15252::I did:
line 29:
Weapon.Stats stats = weapon.GetStats();
in the second image, which is in the Projectile scriptline 20:
return weapon.GetDamage()
in the third image, which is in the WeaponEffect scriptJuly 11, 2024 at 10:29 pm #15255::In both cases, your
weapon
variable is null. You need to figure out which projectile is firing this, and why theweapon
variable is null.July 11, 2024 at 11:14 pm #15258July 11, 2024 at 11:23 pm #15263::Do you think that could be related to the weird spawning of the prefab?
I don’t think so. Did you copy the scripts from the blog entirely? There are parts of the scripts that assign the
weapon
variable. I don’t see it in yourWeaponEffects.cs
script (image 3).July 12, 2024 at 4:08 pm #15273::I got checked the Weapon effect script for part 15, that’s all there was in there. Do I need a later script? What’s missing?
July 12, 2024 at 11:28 pm #15275::My bad, I misremembered. The owner of the
WeaponEffect
(i.e. Projectiles or Auras) is the one that sets it. Check theAttack()
function of your weapon for the highlighted line below:protected override bool Attack(int attackCount = 1) { // If no projectile prefab is assigned, leave a warning message. if(!currentStats.projectilePrefab) { Debug.LogWarning(string.Format("Projectile prefab has not been set for {0}", name)); currentCooldown = data.baseStats.cooldown; return false; } // Can we attack? if (!CanAttack()) return false; // Otherwise, calculate the angle and offset of our spawned projectile. float spawnAngle = GetSpawnAngle(); // And spawn a copy of the projectile. Projectile prefab = Instantiate( currentStats.projectilePrefab, owner.transform.position + (Vector3)GetSpawnOffset(spawnAngle), Quaternion.Euler(0, 0, spawnAngle) ); prefab.weapon = this; prefab.owner = owner; // Reset the cooldown only if this attack was triggered by cooldown. if(currentCooldown <= 0) currentCooldown += currentStats.cooldown; attackCount--; // Do we perform another attack? if (attackCount > 0) { currentAttackCount = attackCount; currentAttackInterval = data.baseStats.projectileInterval; } return true; }
July 16, 2024 at 3:40 pm #15292::That´s exactly what my projectileWeapon script looks like. I wanted to see if the damage actually changes or if it cant get the damage at all. But I don´t know where to do a Debug log to do that.
July 16, 2024 at 5:40 pm #15295::The damage data is in the
Projectile
script. Here it is:protected virtual void OnTriggerEnter2D(Collider2D other) { EnemyStats es = other.GetComponent
(); BreakableProps p = other.GetComponent (); // Only collide with enemies or breakable stuff. if(es) { // If there is an owner, and the damage source is set to owner, // we will calculate knockback using the owner instead of the projectile. Vector3 source = damageSource == DamageSource.owner && owner ? owner.transform.position : transform.position; // Deals damage and destroys the projectile. es.TakeDamage(GetDamage(), source); Weapon.Stats stats = weapon.GetStats(); piercing--; if(stats.hitEffect) { Destroy(Instantiate(stats.hitEffect, transform.position, Quaternion.identity), 5f); } } else if(p) { p.TakeDamage(GetDamage()); piercing--; Weapon.Stats stats = weapon.GetStats(); if (stats.hitEffect) { Destroy(Instantiate(stats.hitEffect, transform.position, Quaternion.identity), 5f); } } // Destroy this object if it has run out of health from hitting other stuff. if(piercing <= 0) Destroy(gameObject); } -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: