- Home /
Collider2D trigger still acts like a collider
I am very new to Unity, and have even less experience in c#. I am trying to implement an attack like explained in this tutorial, https://www.youtube.com/watch?v=xwPahXLpNh8 , using the default Unity 2d platformer template, and I stumbled upon the problem that my collider2D that should be the area of damage is acting like a solid instead, despite the "IsTrigger" checkbox being set. I have no idea why, the only two interactions it have in script is like in the tutorial, the one that turns the triggers on and off,
public class PlayerAttack : MonoBehaviour
{
public bool Attacking = false;
public float AttackTimer = 0;
public float AttackDelay = 14.5f;
public Collider2D AttackTrigger;
Animator anim;
// Start is called before the first frame update
void Start()
{
anim = gameObject.GetComponent<Animator>();
AttackTrigger.enabled = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("q") && !Attacking)
{
Attacking = true;
AttackTimer = AttackDelay;
AttackTrigger.enabled = true;
}
if (Attacking)
{
if (AttackTimer > 0)
{
AttackTimer = Mathf.Clamp (AttackTimer - Time.deltaTime,0,9999);
}
else
{
AttackTrigger.enabled = false;
Attacking = false;
}
}
anim.SetBool("Attacking", Attacking);
}
}
and the one that handles the actual intersection
public class AttackTrigger : MonoBehaviour
{
public int Damage = 1;
public EDamageType DamageKind = EDamageType.Generic;
public void OnTriggerEnter2D(Collider2D col)
{
if (col.isTrigger != true)
{
DamageStorage TempDamageStorage = new DamageStorage (Damage, DamageKind);
col.SendMessageUpwards("DoDamage", TempDamageStorage);
}
}
}
Any idea what might be messing this up?
Answer by Darth_Biomech · Nov 30, 2019 at 07:47 AM
Oh, I traced down the issue. The culprit was KinematicObject.cs, the fuction contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer));
was counting all the colliders in prefab.
I added it's own separate RigidBody2D to the trigger object, and everything began to work as intended!