Forum begins after the advertisement:


[Part 4] Issue with damage dealing on animated garlic

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 4] Issue with damage dealing on animated garlic

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17303
    Jukers
    Level 3
    Participant
    Helpful?
    Up
    1
    ::

    Hey guys! Im on part 4 of the tutorial, applying damage for melee weapons. I have made my garlic animated, when i deal damage with it, the damage get aplied wrongly (like 100 times). i believe that its because of the animation that i did (maybe the animation resets the garlic damage cooldown?) i put a Debug.log on the GarlicBehaviour.cs and it get applied a LOT of times

        protected override void OnTriggerEnter2D(Collider2D col)
        {
            if (col.CompareTag("Enemy") && !markedEnemies.Contains(col.gameObject))
            {
                EnemyStats enemy = col.GetComponent<EnemyStats>();
                enemy.TakeDamage(currentDamage);
                Debug.Log("damage done");
                markedEnemies.Add(col.gameObject);  //Mark the enemy
            }
        }
    }
    

    Debug.log(“damage done”) 94 times in less than a second

    If thats the issue i think it is, is there some way to “ignore” the animation when i make the garlic do damage? If thats not the actual issue, let me know!

    has upvoted this post.
    #17304
    Jukers
    Level 3
    Participant
    Helpful?
    Up
    1
    ::

    After about an hour of searching and debbuging i found out i forgot a line at the GarlicController

    
    using UnityEngine;
    
    public class GarlicController : WeaponController
    {
    
    
        protected override void Start()
        {
            base.Start(); //<without this line the garlic gets instantiated a lot of times, dealing infinite dmg
        }
    
        // Update is called once per frame
        protected override void Attack()
        {
            base.Attack();
            GameObject spawnedGarlic = Instantiate(weaponData.Prefab);
            spawnedGarlic.transform.position = transform.position; //coloca a posicao do objeto como sendo a mesma que do seu pai (player)
            spawnedGarlic.transform.parent = transform; //spawna abaixo do objeto
        }
    }
    
    has upvoted this post.
    #17305
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    That’s a great spot Jukers. Glad you managed to find the fix on your own as well.

    Just a heads up that in Parts 15 and 16, we overhaul the weapon system to make it more flexible, and recode the garlic weapon as well. The implementation of the weapon in Part 4 doesn’t work exactly the same way that the one in the game does.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: