Пример #1
0
 private void OnTriggerExit(Collider other)
 {
     if (Bullet == other.GetComponent <BulletCollider>())
     {
         Bullet = null;
     }
 }
Пример #2
0
    public override EnemyAIStateType Tick()
    {
        NearestBullet = controller.NearestBullet;

        if (NearestBullet == null)
        {
            return(EnemyAIStateType.Search);
        }

        Vector3 nearestBulletVelocity = NearestBullet.rb.velocity;
        Vector2 direction             = Vector2.Perpendicular(new Vector2(nearestBulletVelocity.x, nearestBulletVelocity.y));

        Vector3 moveDirection = new Vector3(direction.x, 0, direction.y);

        if (Vector3.Distance(moveDirection + transform.position, NearestBullet.transform.position) <
            Vector3.Distance(transform.position - moveDirection, NearestBullet.transform.position))
        {
            moveDirection *= -1;
        }

        Debug.DrawRay(transform.position, moveDirection, Color.blue);
        Debug.DrawRay(NearestBullet.transform.position, moveDirection, Color.blue);

        controller.TargetDestination = transform.position + moveDirection;


        return(GetStateType());
    }
Пример #3
0
    private void OnCollisionEnter(Collision collision)
    {
        BulletCollider bulletCollider = collision.collider.GetComponent <BulletCollider>();

        if (bulletCollider)
        {
            ProjectileWeapon weapon = bulletCollider.GetComponent <ProjectileWeapon>();
            //dont do anything if this projectile collides with
            //the person who shot it
            if (weapon != firerWeapon)
            {
                bulletCollider.BulletCollision(this);

                if (bulletCollider.KillBullet)
                {
                    Kill();
                }
                else
                {
                    //It has a bullet collider but is set to not 'kill' the bullet.
                    //so we assume the bullet should 'Bounce' off the surface
                    foreach (ContactPoint c in collision.contacts) //Find collision point
                    {
                        rigid.velocity          = Quaternion.AngleAxis(180, c.normal) * transform.forward * -1;
                        rigid.velocity          = rigid.velocity.normalized * speed * timeManager.Coefficient;
                        rigid.transform.forward = rigid.velocity.normalized;
                    }
                }
            }
        }
    }
 private void OnTriggerExit(Collider other)
 {
     if (Bullet == other.GetComponent <BulletCollider>())
     {
         Bullet = null;
         OnAddDangerousBulletTrigger(Bullet);
     }
 }
Пример #5
0
 /// <summary>
 /// checks if the animation is over and if so removes damage hp from the player if they are in range
 /// </summary>
 protected void Attacking()
 {
     if (Sprite.IsAtStartOfFrame(damageFrame))
     {
         if (BulletCollider.Intersects(SceneManager.gameScene.player.BulletCollider))
         {
             SoundManager.playerHurt.Play();
             SceneManager.gameScene.player.Health   -= Damage;
             SceneManager.gameScene.player.bleeding += .001f; // maybe this should be different for different zombies
         }
     }
     else if (Sprite.EndOfAnim)
     {
         attacking = false;
     }
 }
Пример #6
0
    private void OnTriggerEnter(Collider other)
    {
        BulletCollider bulletCollider = other.GetComponent <BulletCollider>();

        if (bulletCollider)
        {
            ProjectileWeapon weapon = bulletCollider.GetComponent <ProjectileWeapon>();
            //dont do anything if this projectile collides with
            //the person who shot it
            if (weapon != firerWeapon)
            {
                bulletCollider.BulletCollision(this);

                if (bulletCollider.KillBullet)
                {
                    Kill();
                }
            }
        }
    }
    private void SetBullet(BulletCollider other)
    {
        Transform otherTransform = other.transform;
        Vector2   perpendicular2 = Vector2.Perpendicular(otherTransform.forward).normalized;
        Vector3   perpendicular  = new Vector3(perpendicular2.x, 0f, perpendicular2.y);
        bool      hitMe          = Physics.Raycast(otherTransform.position, otherTransform.forward, out RaycastHit objectHit, 100f) &&
                                   objectHit.transform.position == transform.position;
        bool hitMeLeft = Physics.Raycast(otherTransform.position + perpendicular, otherTransform.forward, out RaycastHit objectHitLeft, 100f) &&
                         objectHitLeft.transform.position == transform.position;
        bool hitMeRight = Physics.Raycast(otherTransform.position - perpendicular, otherTransform.forward, out RaycastHit objectHitRight, 100f) &&
                          objectHitRight.transform.position == transform.position;

        //Debug
        Debug.DrawRay(otherTransform.position, otherTransform.forward, Color.red);
        Debug.DrawRay(otherTransform.position + perpendicular, otherTransform.forward, Color.red);
        Debug.DrawRay(otherTransform.position - perpendicular, otherTransform.forward, Color.red);


        if (hitMe || hitMeLeft || hitMeRight)
        {
            //Debug.Log("Incoming bullet");
            var  bulletDistance = Bullet == null ? 0f : Mathf.Abs(Vector3.Distance(transform.position, Bullet.transform.position));
            var  otherDistance  = Mathf.Abs(Vector3.Distance(transform.position, otherTransform.position));
            bool bulletIsCloser = Bullet != null && (otherDistance >= bulletDistance);
            if (!bulletIsCloser)
            {
                Bullet = other;
                OnAddDangerousBulletTrigger(Bullet);
            }
        }
        else if (Bullet == other)
        {
            Bullet = null;
            OnAddDangerousBulletTrigger(Bullet);
        }
    }
Пример #8
0
    private BulletCollider bulletCollider; // The BulletCollider component of this bullet object

    private void Awake()
    {
        // Component reference assignments
        bulletData     = this.gameObject.GetComponent <BulletData>();
        bulletCollider = this.gameObject.GetComponent <BulletCollider>();
    }
 private void OnAddDangerousBulletTrigger(BulletCollider bullet)
 {
     AddDangerousBullet?.Invoke(bullet);
 }
 private void BulletDetector_AddDangerousBullet(BulletCollider _bullet)
 {
     NearestBullet = _bullet;
 }
Пример #11
0
 public void AddMonoBehavior()
 {
     mBulletCollider = mBullet.AnyBullet.GetComponent <BulletCollider>();
     mBulletCollider.SetCollider(mBullet); //子弹伤害设置
     mBulletCollider.Init();
 }
Пример #12
0
 private void NearestBulletCollider_AddDangerousBullet(BulletCollider bullet)
 {
     NearestBullet = bullet;
 }
Пример #13
0
    private void OnCollisionEnter(Collision other)
    {
        TankData       otherTankData       = other.gameObject.GetComponent <TankData>();
        BulletCollider otherBulletCollider = other.gameObject.GetComponent <BulletCollider>();

        if (otherTankData == bulletData.bulletOwner)
        {
            Physics.IgnoreCollision(this.gameObject.GetComponent <Collider>(), other.collider);
            return;
        }
        // If this bullet hits a tank
        else if (otherTankData != null)
        {
            // If this bullet was fired by a player tank
            if (this.tag == "Player")
            {
                // Bullet collided with an enemy tank, or collided with a player tank and friendly fire is enabled
                if (other.gameObject.tag == "Enemy" ||
                    (other.gameObject.tag == "Player" && GameManager.gm.friendlyFire))
                {
                    // Damages the tank
                    int otherTankHP = otherTankData.tankHealthMan.Damage(bulletData.bulletDamage);

                    // If the other tank was destroyed by this shot
                    if (otherTankHP != -1)
                    {
                        bulletData.bulletOwner.tankScorer.IncreaseScore(otherTankHP);
                    }
                }
                else
                {
                    // Nothing to do but go die
                }
            }
            // If this bullet was fired by an enemy tank
            else if (this.tag == "Enemy")
            {
                // Bullet collided with a player tank, or collided with an enemy tank and enemy friendly fire is enabled
                if (other.gameObject.tag == "Player" ||
                    (other.gameObject.tag == "Enemy" && GameManager.gm.enemyFriendlyFire))
                {
                    // Damages the tank
                    otherTankData.tankHealthMan.Damage(bulletData.bulletDamage);
                }
                else
                {
                    // Nothing to do but go die
                }
            }
        }
        // Ignore bullet collisions
        else if (otherBulletCollider != null && !GameManager.gm.bulletCollisions)
        {
            Physics.IgnoreCollision(this.GetComponent <Collider>(), other.collider);
            //this.gameObject.GetComponent<Collider>().enabled = false;
            return;
        }
        else
        {
            // Do nothing else except go die
        }
        GameManager.soundMgr.PlayBulletHitSound();
        Die();
    }