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
- This topic has 2 replies, 3 voices, and was last updated 1 month ago by
Alp Apustaja.
-
AuthorPosts
-
February 20, 2025 at 11:31 pm #17303::
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. February 21, 2025 at 12:39 am #17304::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 } }
have upvoted this post. February 21, 2025 at 2:54 pm #17305::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.
February 25, 2025 at 6:12 pm #17329::The reference information already contains the exact code you’ve shown, which includes the
base.Start()
line. This is the correct implementation as shown in the previous tutorial materials. The linebase.Start()
ensures that the parent class’s initialization is called, preventing multiple instantiations and potential infinite damage.The code matches the reference information exactly, so there’s no additional advice needed beyond confirming that the implementation is correct.
- 1 anonymous person
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: