Beispiel #1
0
 public override void SettedEvent()
 {
     base.SettedEvent();
     Collider[] rays = Physics.OverlapSphere(transform.position, Radius);
     for (int i = 0; i < rays.Length; i++)
     {
         if (rays[i].transform.tag == "Item" || rays[i].transform.tag == "IgnoreMe")
         {
             continue;
         }
         if (rays[i].transform.root.gameObject.tag == "Player")
         {
             if (rays[i].gameObject.transform.root.GetComponent <PlayerHitten>())
             {
                 BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                 bulletHitInfo.hitTransform = rays[i].transform;
                 bulletHitInfo.bulletForce  = (rays[i].ClosestPoint(transform.position) - transform.position).normalized * 1000;
                 // bulletHitInfo.hitNormal = raycastHit.normal;
                 bulletHitInfo.hitPoint = rays[i].ClosestPoint(transform.position);
                 bulletHitInfo.IsShot   = true;
                 rays[i].gameObject.transform.root.GetComponent <PlayerHitten>().OnHit(bulletHitInfo);
                 Destroy(Instantiate(VFX, transform.position, Quaternion.identity), 3f);
                 Destroy(this.gameObject);
             }
         }
     }
 }
Beispiel #2
0
    private void OnTriggerStay(Collider other)
    {
        if (!IsAttacking)
        {
            return;
        }
        if ((layerMask.value & 1 << other.gameObject.layer) > 0)
        {
            if (other.gameObject.transform.root.GetComponent <PlayerHitten>())
            {
                if (other.gameObject.transform.root.GetComponent <PlayerIdentity>().PlayerID == PlayerID)
                {
                    return;
                }
                PlayerHitten     hitten        = other.gameObject.transform.root.GetComponent <PlayerHitten>();
                BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                bulletHitInfo.hitTransform = other.transform;
                bulletHitInfo.bulletForce  = (other.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                // bulletHitInfo.hitNormal = raycastHit.normal;
                bulletHitInfo.hitPoint = other.ClosestPoint(transform.position);

                if (!playerHittens.Contains(hitten))
                {
                    hitten.OnDamaged(damage, PlayerID);
                    hitten.OnHit(bulletHitInfo);
                    playerHittens.Add(hitten);
                    Instantiate(HitParticle, bulletHitInfo.hitPoint, Quaternion.identity);
                    audioSource.PlayOneShot(HitSFX, volume);
                }
            }
            else if (other.gameObject.transform.root.GetComponent <CreatureBasic>())
            {
                other.gameObject.transform.root.GetComponent <CreatureBasic>().Death();
                other.GetComponent <Rigidbody>().AddForceAtPosition((other.ClosestPoint(transform.position) - transform.position).normalized * velocity * 2, other.ClosestPoint(transform.position));
                Instantiate(HitParticle, other.ClosestPoint(transform.position), Quaternion.identity);
                audioSource.PlayOneShot(HitSFX, volume);
            }


            if (other.gameObject.tag == "Item")
            {
                if (other.gameObject.GetComponent <ItemBasic>())
                {
                    ItemBasic itemBasic = other.gameObject.GetComponent <ItemBasic>();

                    // 記得取消
                    // itemBasic.OnUse();

                    if (!itemBasic.IsHolded)
                    {
                        BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                        bulletHitInfo.hitTransform = other.transform;
                        bulletHitInfo.bulletForce  = (other.ClosestPoint(transform.position) - transform.position).normalized * velocity / 30;
                        bulletHitInfo.hitPoint     = other.ClosestPoint(transform.position);
                        itemBasic.AddForce(bulletHitInfo);
                    }
                }
            }
        }
    }
Beispiel #3
0
    IEnumerator AddForceToLimb(BulletHitInfo_AF bulletHitInfo)
    {
        if (!IsInvincible && !IsAxe)
        {
            yield return(new WaitForFixedUpdate());

            if (bulletHitInfo.hitTransform != null)
            {
                if (bulletHitInfo.hitTransform.GetComponent <Rigidbody>() != null)
                {
                    bulletHitInfo.hitTransform.GetComponent <Rigidbody>().AddForceAtPosition(bulletHitInfo.bulletForce, bulletHitInfo.hitPoint);
                }
            }
            playerMove.AddForceSpeed(bulletHitInfo.bulletForce / 100f);

            // 最好設成一個Global Ienumertor 比較方便
            if (gamepad != null)
            {
                gamepad.SetMotorSpeeds(0.8f, 1f);
                yield return(new WaitForSecondsRealtime(0.2f));

                gamepad.PauseHaptics();
            }
        }
    }
Beispiel #4
0
    IEnumerator explosion()
    {
        yield return(new WaitForSecondsRealtime(delay));

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layerMask);

        BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();

        foreach (Collider collider in colliders)
        {
            if ((layerMask.value & 1 << collider.gameObject.layer) > 0)
            {
                if (collider.gameObject.transform.root.GetComponent <PlayerHitten>())
                {
                    PlayerHitten hitten = collider.gameObject.transform.root.GetComponent <PlayerHitten>();
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    // bulletHitInfo.hitNormal = raycastHit.normal;
                    bulletHitInfo.hitPoint = collider.ClosestPoint(transform.position);

                    if (!playerHittens.Contains(hitten))
                    {
                        hitten.OnDamaged(damage, PlayerID);
                    }

                    hitten.OnHit(bulletHitInfo);

                    playerHittens.Add(hitten);
                }
                else if (collider.gameObject.transform.root.GetComponent <CreatureBasic>())
                {
                    collider.gameObject.transform.root.GetComponent <CreatureBasic>().Death();
                    collider.GetComponent <Rigidbody>().AddForceAtPosition((collider.ClosestPoint(transform.position) - transform.position).normalized * velocity * 2, collider.ClosestPoint(transform.position));
                }
            }

            if (collider.gameObject.tag == "Item")
            {
                Debug.Log(collider.gameObject.name);
                if (collider.gameObject.GetComponent <ItemBasic>())
                {
                    ItemBasic itemBasic = collider.gameObject.GetComponent <ItemBasic>();

                    // 記得取消
                    // itemBasic.OnUse();

                    if (itemBasic.IsHolded)
                    {
                        continue;
                    }
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    bulletHitInfo.hitPoint     = collider.ClosestPoint(transform.position);
                    itemBasic.AddForce(bulletHitInfo);
                }
            }
        }
        yield return(null);
    }
Beispiel #5
0
    // 亂寫的
    IEnumerator ReSpawn()
    {
        BulletHitInfo_AF bulletHitInfo_AF = new BulletHitInfo_AF();

        transform.root.GetComponent <PlayerHitten>().OnHit(bulletHitInfo_AF);
        transform.root.GetComponent <PlayerIdentity>().Respawn();
        yield return(null);
    }
Beispiel #6
0
    IEnumerator AddForceToLimb(BulletHitInfo_AF bulletHitInfo)
    {
        yield return(new WaitForFixedUpdate());

        if (bulletHitInfo.hitPoint != null)
        {
            bulletHitInfo.hitTransform.GetComponent <Rigidbody>().AddForceAtPosition(bulletHitInfo.bulletForce, bulletHitInfo.hitPoint);
        }
    }
Beispiel #7
0
 public void OnHit(BulletHitInfo_AF info)
 {
     ragdollControl.shotByBullet = true;
     if (Flag != null)
     {
         Flag.Throw();
     }
     Flag = null;
     pickItem.OnHit(info);
     StartCoroutine(AddForceToLimb(info));
 }
Beispiel #8
0
 // 亂寫的
 IEnumerator ReSpawn()
 {
     if (!transform.root.GetComponent <PlayerHitten>().Dead)
     {
         Debug.Log("Death");
         BulletHitInfo_AF bulletHitInfo_AF = new BulletHitInfo_AF();
         transform.root.GetComponent <PlayerHitten>().OnHit(bulletHitInfo_AF);
         transform.root.GetComponent <PlayerHitten>().AddtionalDeath();
     }
     yield return(null);
 }
Beispiel #9
0
 public void OnHit(BulletHitInfo_AF info)
 {
     Destroy(Instantiate(HitParticle, info.hitPoint, Quaternion.identity), 2f);
     // GetComponent<Rigidbody>().AddForce(info.bulletForce);
     if (IsHolding)
     {
         itemHand.DropHoldingItem(info.bulletForce);
         IsHolding   = false;
         IsThrowing  = false;
         IsThrowing2 = false;
     }
 }
Beispiel #10
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.layer == LayerMask.NameToLayer("Water"))
     {
         Debug.Log(2);
         BulletHitInfo_AF bulletHitInfo_AF = new BulletHitInfo_AF();
         bulletHitInfo_AF.bulletForce = Vector3.zero;
         // bulletHitInfo.hitNormal = raycastHit.normal;
         bulletHitInfo_AF.hitTransform = other.transform;
         bulletHitInfo_AF.hitPoint     = other.ClosestPoint(transform.position);
         other.transform.root.gameObject.GetComponent <PlayerHitten>().OnHit(bulletHitInfo_AF);
         Destroy(this.gameObject);
     }
 }
Beispiel #11
0
    public void EventOnHit(BulletHitInfo_AF info)
    {
        StartCoroutine(EventAddForceToLimb(info));

        if (ragdollControl.shotByBullet)
        {
            return;
        }

        if (info.IsShot)
        {
            ragdollControl.shotByBullet = true;
        }
        else
        {
        }
        if (!IsInvincible)
        {
            pickItem.OnHit(info);
        }
    }
Beispiel #12
0
    IEnumerator explosion()
    {
        yield return(new WaitForSecondsRealtime(delay));

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layerMask);
        foreach (Collider collider in colliders)
        {
            if ((layerMask.value & 1 << collider.gameObject.layer) > 0)
            {
                if (collider.gameObject.transform.root.GetComponent <PlayerHitten>())
                {
                    BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    // bulletHitInfo.hitNormal = raycastHit.normal;
                    bulletHitInfo.hitPoint = collider.ClosestPoint(transform.position);
                    collider.gameObject.transform.root.GetComponent <PlayerHitten>().OnHit(bulletHitInfo);
                }
                else if (collider.gameObject.transform.root.GetComponent <CreatureBasic>())
                {
                    Destroy(collider.gameObject);
                }
            }

            if (collider.gameObject.tag == "Item")
            {
                if (collider.gameObject.transform.root.GetComponent <ItemBasic>())
                {
                    BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();
                    bulletHitInfo.hitTransform = collider.transform;
                    bulletHitInfo.bulletForce  = (collider.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                    bulletHitInfo.hitPoint     = collider.ClosestPoint(transform.position);
                    collider.gameObject.transform.root.GetComponent <ItemBasic>().AddForce(bulletHitInfo);
                }
            }
        }
        yield return(null);
    }
Beispiel #13
0
    public static void ThrowPlayer(int i)
    {
        /*player.GetComponentInChildren<SimpleFootIK_AF>().followTerrain = true;
         * player.GetComponentInChildren<PlayerMove>().AddForceSpeed(new Vector3(0, 0, 200));*/
        if (i >= players.Count)
        {
            return;
        }

        BulletHitInfo_AF bulletHitInfo_AF = new BulletHitInfo_AF();

        Collider[] colliders = players[i].GetComponent <PlayerHitten>().Hips.GetComponentsInChildren <Collider>();
        // Vector3 p = player.GetComponent<PlayerHitten>().Hips.position - new Vector3( 0, 0, -1);
        Vector3 p = new Vector3(0, 3f, -15.5f + i * -1f);

        int j = 0;

        foreach (Collider collider in colliders)
        {
            if (j % 2 != 0)
            {
                continue;
            }
            bulletHitInfo_AF.IsShot       = true;
            bulletHitInfo_AF.hitTransform = collider.transform;
            bulletHitInfo_AF.bulletForce  = (collider.ClosestPoint(p) - p).normalized * (20000 + i * 10000);
            bulletHitInfo_AF.hitPoint     = collider.ClosestPoint(p);

            players[i].GetComponent <PlayerHitten>().EventOnHit(bulletHitInfo_AF);
            players[i].GetComponent <PlayerIdentity>().InputEnable();
            j++;
        }
        players[i].GetComponentInChildren <SimpleFootIK_AF>().followTerrain = true;

        /*foreach (GameObject player in players)
         * {
         * }*/
    }
Beispiel #14
0
    public void OnHit(BulletHitInfo_AF info)
    {
        // GetComponent<Rigidbody>().AddForce(info.bulletForce);
        ThrowStrength = 3f;
        ThrowPower1   = 0.01f;

        if (IsCharging)
        {
            playerStatus.PlayerItemAnimation("_Interupt");
            IsCharging = false;
        }
        if (IsThrowing)
        {
            playerStatus.CancelThrow();
        }
        if (IsHolding)
        {
            itemHand.DropHoldingItem(info.bulletForce / 10);
            IsHolding   = false;
            IsThrowing  = false;
            IsThrowing2 = false;
        }
    }
Beispiel #15
0
 public void AddForce(BulletHitInfo_AF bulletHitInfo)
 {
     bulletHitInfo.hitTransform.GetComponent <Rigidbody>().AddForceAtPosition(bulletHitInfo.bulletForce, bulletHitInfo.hitPoint);
 }
Beispiel #16
0
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log(other.gameObject.name);
        if (time < CollisionDelay)
        {
            return;
        }
        if (!IsEnable)
        {
            return;
        }
        if (!((TargetMask.value & 1 << other.gameObject.layer) > 0))
        {
            return;
        }
        foreach (Basic_Bullet b in basic_Bullets)
        {
            if (b != null)
            {
                if (other.transform == b.transform)
                {
                    return;
                }
            }
        }

        BulletHitInfo_AF bulletHitInfo = new BulletHitInfo_AF();

        if ((PlayerMask.value & 1 << other.gameObject.layer) > 0)
        {
            if (other.gameObject.transform.root.GetComponent <PlayerHitten>())
            {
                PlayerHitten hitten = other.gameObject.transform.root.GetComponent <PlayerHitten>();
                bulletHitInfo.hitTransform = other.transform;
                bulletHitInfo.bulletForce  = (other.ClosestPoint(transform.position) - transform.position).normalized * velocity;
                // bulletHitInfo.hitNormal = raycastHit.normal;
                bulletHitInfo.hitPoint = other.ClosestPoint(transform.position);

                if (!playerHittens.Contains(hitten))
                {
                    hitten.OnDamaged(damage, PlayerID);
                    hitten.OnHit(bulletHitInfo);
                    playerHittens.Add(hitten);
                }
            }
        }
        else
        {
            if (other.gameObject.transform.root.GetComponent <CreatureBasic>())
            {
                CreatureBasic creatureBasic = other.gameObject.transform.root.GetComponent <CreatureBasic>();
                creatureBasic.Death();
            }
            other.GetComponent <Rigidbody>().AddForceAtPosition((other.ClosestPoint(transform.position) - transform.position).normalized * velocity, other.ClosestPoint(transform.position));
        }
        GameObject g = Instantiate(CollisionEffect, transform.position, transform.rotation);

        Destroy(g, 2f);
        Destroy(this.gameObject, DestroyAfterCollision);
        rb.isKinematic = true;
        IsEnable       = false;
    }