Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        EnemyDamagable damagable = InteractiveHelpers.GetEnemy(collision);

        if (damagable)
        {
            damagable.TakeDamageFrom(boxCollider, controller);
            if (damagable.HasRecoilAfterDamage())
            {
                controller.di.stateMachine.SetRecoilState(damagable.GetRecoilAfterDamage());
            }
        }
    }
    public bool IsSwordFalling(EnemyDamagable enemy)
    {
        if (!isSword)
        {
            return(false);
        }
        Vector2 playerCenter          = controller.di.boxCollider.bounds.center;
        Vector2 enemyCenter           = enemy.ColliderCenter;
        Vector2 playerToEnemyDistance = enemyCenter - playerCenter;
        bool    enemyBelow            = playerToEnemyDistance.y < 0;
        bool    isFalling             = !physics.IsGrounded;

        return(enemyBelow && isFalling);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        bool isFalling = physics.velocity.Y < 0;

        if (isFalling)
        {
            EnemyDamagable damagable = InteractiveHelpers.GetEnemy(collision);
            if (damagable)
            {
                damagable.TakeDamageFrom(boxCollider, controller);
                if (damagable.HasRecoilAfterDamage())
                {
                    controller.di.stateMachine.SetRecoilState(damagable.GetRecoilAfterDamage());
                }
                else
                {
                    Vector2 playerRecoil = RecoilHelpers.GetRecoilFromTo(controller.transform, controller.transform, tileRecoilOnHit);
                    Debug.Log(playerRecoil);
                    physics.velocity.Value = playerRecoil;
                    //controller.StateMachine.SetRecoilState(playerRecoil);
                }
            }
        }
    }