- Home /
,Why does OnTriggerEnter2D consider the the child as it's parent ?
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Weapon")
{
hitpoint -= InventoryManager.GetPlayerAttributeMaxValue("Damage");
Vector2 diff = transform.position - other.transform.position;
transform.position = new Vector2(transform.position.x + diff.x, transform.position.y + diff.y);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (Time.time > cdEnd)
{
if (other.tag == "Enemy")
{
enemyDamage = other.gameObject;
damageAm = enemyDamage.GetComponent<Fighter>().damage;
curHP = InventoryManager.GetPlayerAttributeCurrentValue("Health");
curHP -= damageAm;
InventoryManager.SetPlayerAttributeValue("Health", curHP, 0);
cdEnd = Time.time + damagedCD;
}
}
so what i did is making a sword and putting it as player's child the first script is when an enemy collides with the sword it checks the tag of it to see if it's a weapon or not if yes it get damaged the second is checking if the object that collided with the player is an enemy or not if yes the player get damaged so the problem is that when the enemy collides with the sword the enemy is damaged but the player is damaged also even tho the enemy didn't collide with the player it collided with the sword i tried making the sword an object of it's own and not the player's child but it just makes the enemy can't trigger the sword collider what is the problem exactly ? and what can i do to make it work right ?
Answer by Yushiro010 · Nov 17, 2021 at 09:31 AM
nvm the problem was simple i just didn't put a rigidbody on the sword that's all
Your answer
Follow this Question
Related Questions
2018.2.17 OnTriggerEnter2D not working 1 Answer
Weird problem with triggers 0 Answers
Trigger Triggers Without Collision 1 Answer
only player can activate triggers? 1 Answer
how do I use the same script for 2 different purposes? 1 Answer