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

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #15249
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    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

    #15250
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I also get these errors everytime the weapon/player is in the vicinity of an enemy:

    View post on imgur.com

    #15251
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you post the lines in your code that are highlighted by the error log?

    #15252
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    I did:

    View post on imgur.com

    line 29: Weapon.Stats stats = weapon.GetStats(); in the second image, which is in the Projectile script

    line 20: return weapon.GetDamage() in the third image, which is in the WeaponEffect script

    #15255
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    In both cases, your weapon variable is null. You need to figure out which projectile is firing this, and why the weapon variable is null.

    #15258
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Do you think that could be related to the weird spawning of the prefab?

    #15263
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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 your WeaponEffects.cs script (image 3).

    #15273
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    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?

    #15275
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    My bad, I misremembered. The owner of the WeaponEffect (i.e. Projectiles or Auras) is the one that sets it. Check the Attack() 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;
        }
    #15292
    Nihkto
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    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.

    #15295
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    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);
    }
Viewing 11 posts - 16 through 26 (of 26 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: