Collider won't trigger if my player isn't moving in 2D

Viewed 103

PLAYER = Ninja Boy ENEMY = Ninja girl

I have two game objects, one is enemy and the other is player both having colliders2D and rigidbody2D. I made a script for enemy chase my when i;m in his sight(i made a boxcollider2d for this) and when he's close enought he start's attacking. To detect collision between he's sword and me i made an edge collider that he enables it when starts attacking and disable when the attack animation is done
here is the enemy with the sword collider

The problem is that when i don't move, the player OnEnterTrigger2D function doesn't detect the collision if i'm in this position (the player is clearly inside the collider) enter image description here

This is the Player class

    public override IEnumerator TakeDamage()
    {
        if (!immortal && !IsDead) 
        {
            health -= 10;
            Animator.SetLayerWeight(1, 0);

            if (!IsDead)
            {
                Animator.SetTrigger("damage");
                Rigidbody.velocity = Vector2.zero;
                immortal = true;
                yield return new WaitForSeconds(immortalTimer);
                immortal = false;
            }
        }

        if(IsDead)
        {
            Animator.SetTrigger("dead");
        }
    }

    protected override void OnTriggerEnter2D(Collider2D collider)
    {
        Debug.Log(collider.name);
        base.OnTriggerEnter2D(collider);
    }

and the player inherits from Character

public abstract IEnumerator TakeDamage();

  protected virtual void OnTriggerEnter2D(Collider2D collider)
    {
        if (damagingObjects.Contains(collider.tag))
        {
            StartCoroutine(TakeDamage());
        }
    }

and i noticed that if a manualy activate the enemy's trigger while playing, the player will take damege even if he's not moving

0 Answers
Related