コード例 #1
0
    void HorizontalCollisions(ref Vector2 moveAmount)
    {
        //if (hat.collisionSkip) return;
        Vector2 oldVelocity = hat.velocity;

        float directionX = collisions.faceDir;
        float rayLength  = Mathf.Abs(moveAmount.x) + skinWidth;

        if (Mathf.Abs(moveAmount.x) < skinWidth)
        {
            rayLength = 2 * skinWidth;
        }

        for (int i = 0; i < horizontalRayCount; i++)
        {
            Vector2 rayOrigin = (directionX == -1)?raycastOrigins.bottomLeft:raycastOrigins.bottomRight;
            rayOrigin += Vector2.up * (horizontalRaySpacing * i);
            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, collisionMask);

            Debug.DrawRay(rayOrigin, Vector2.right * directionX, Color.red);

            if (hit)
            {
                if (hit.distance == 0)
                {
                    //continue;
                }

                if (hit.collider.CompareTag("Ignore"))
                {
                    continue;
                }

                if (hit.collider.CompareTag("Target"))
                {
                    if (hat.isCurrentlyAttached || hat.isBeingAttached)
                    {
                        continue;
                    }

                    if (hat.isBeingThrown)
                    {
                        hat.ApplyFreezeFrames(5);

                        VFXManager.instance.EmitAtPosition("Target_Explosion", 30, hit.transform.position, true);

                        PlayHitEffect(hit, Vector3.zero, hat.velocity, hat.lastVelocity);

                        Destroy(hit.collider.gameObject);

                        collisions.shouldReflect = true;
                        hat.collisionSkip        = false;
                    }
                    else
                    {
                        continue;
                    }
                }

                if (hit.transform.CompareTag("Balloon"))
                {
                    if (hat.isCurrentlyAttached || hat.isBeingAttached)
                    {
                        continue;
                    }

                    if (hat.isBeingThrown)
                    {
                        hat.ApplyFreezeFrames(5);
                        hat.owner.ApplyFreezeFrames(5);

                        VFXManager.instance.EmitAtPosition("Balloon_Explosion", 30, hit.transform.position, true);
                        VFXManager.instance.EmitAtPosition("Balloon_Lines", 1, hit.transform.position, true);

                        PlayHitEffect(hit, Vector3.zero, hat.velocity, hat.lastVelocity);

                        Destroy(hit.transform.gameObject);

                        collisions.shouldReflect = true;
                        hat.collisionSkip        = false;
                    }
                    else
                    {
                        hat.collisionSkip = true;
                        continue;
                    }
                }

                if (hit.transform.CompareTag("Icicle") && hat.collisionSkip)
                {
                    Icicle icicle = hit.transform.GetComponent <Icicle>();

                    if (hat.isBeingThrown)
                    {
                        if (icicle.isCurrentlyAttached)
                        {
                            icicle.BreakOff();
                        }

                        icicle.LoseHp();

                        collisions.shouldReflect = true;
                    }
                    else if (!hat.isCurrentlyAttached)
                    {
                        collisions.shouldReflect = true;
                    }

                    hat.collisionSkip = false;
                }

                if (hit.transform.CompareTag("TransferDanger") && hat.collisionSkip)
                {
                    if (hat.isBeingThrown)
                    {
                        hit.transform.GetComponent <TransferDanger>().Transfer(hat.velocity * 1.5f);
                    }

                    collisions.shouldReflect = true;
                    hat.collisionSkip        = false;
                }

                if (hit.transform.CompareTag("MiningCart") && hat.collisionSkip)
                {
                    if (hat.isBeingThrown)
                    {
                        int _direction = collisions.faceDir;

                        hit.transform.GetComponent <MiningCart>().MoveCart(_direction);

                        hat.AllowToComeBack();

                        if (hit.transform.GetComponent <MiningCart>().isDangerous)
                        {
                            PlayHitEffect(hit, hat.velocity, hat.velocity, oldVelocity);
                        }
                    }

                    collisions.shouldReflect = true;
                    hat.collisionSkip        = false;
                }

                if (hat.isBeingAttached && (hit.collider.CompareTag("Player") || hit.collider.CompareTag("Hat") || hit.collider.CompareTag("Lava")))
                {
                    continue;
                }
                if (hat.isBeingAttached && i == 0)
                {
                    continue;
                }

                if (hit.collider.CompareTag("Lava"))
                {
                    collisions.shouldBurn = true;

                    continue;
                }

                if (hit.collider.CompareTag("Smash Ball"))
                {
                    if (hat.isCurrentlyAttached || hat.isBeingAttached)
                    {
                        continue;
                    }

                    if (hat.isBeingThrown)
                    {
                        hat.ApplyFreezeFrames(5);
                        hat.owner.ApplyFreezeFrames(5);

                        PlayHitEffect(hit, Vector3.zero, hat.velocity, hat.lastVelocity);

                        collisions.shouldReflect = true;
                        hat.collisionSkip        = false;
                    }
                    else
                    {
                        hat.collisionSkip = true;
                        continue;
                    }
                }

                if (hit.collider.CompareTag("Player"))
                {
                    Player otherPlayer = hit.collider.GetComponent <Player>();

                    if (hat.isBeingThrown)
                    {
                        if (!otherPlayer.isInvulnerable && !hat.isHitFrozen)
                        {
                            float stunTimeModifier = (hat.hasIncreasingStunOverTime) ? hat.currentThrowTimer : 0;

                            otherPlayer.BlowBack((new Vector3(hit.point.x, hit.point.y, transform.position.z) - transform.position), hat.throwBlowBack, hat.throwStunTime + stunTimeModifier);

                            hat.ApplyFreezeFrames(5);
                            hat.owner.ApplyFreezeFrames(5);
                            otherPlayer.hat.ApplyFreezeFrames(5);
                            otherPlayer.ApplyFreezeFrames(5);

                            PlayHitEffect(hit, hit.collider.GetComponent <Player>().GetVelocity(), hat.velocity, oldVelocity);
                            collisions.isHittingPlayer = true;
                            hat.collisionSkip          = false;
                            hat.AllowToComeBack();

                            CalculateAccuracy();
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                if (hit.collider.CompareTag("Hat"))
                {
                    Hat other = hit.collider.GetComponent <Hat>();

                    if (hat.isFallingOff || other.isFallingOff || hat.isDying)
                    {
                        continue;
                    }

                    if (hat.isBeingThrown)
                    {
                        if (other.isCurrentlyAttached)
                        {
                            if (!other.owner.isInvulnerable)
                            {
                                float stunTimeModifier = (hat.hasIncreasingStunOverTime) ? hat.currentThrowTimer : 0;

                                other.owner.BlowBack((new Vector3(hit.point.x, hit.point.y, transform.position.z) - transform.position), hat.throwBlowBack, hat.throwStunTime + stunTimeModifier);

                                hat.ApplyFreezeFrames(5);
                                hat.owner.ApplyFreezeFrames(5);
                                other.ApplyFreezeFrames(5);
                                other.owner.ApplyFreezeFrames(5);

                                hit.collider.GetComponent <HatController>().collisions.hitHat = true;
                                PlayHitEffect(hit, other.velocity, hat.velocity, oldVelocity);
                                collisions.isHittingPlayer = true;
                                hat.collisionSkip          = false;
                                hat.AllowToComeBack();

                                CalculateAccuracy();
                            }
                        }
                        else if (other.isBeingThrown)
                        {
                            hit.collider.GetComponent <HatController>().collisions.hitHat = true;

                            hat.ApplyFreezeFrames(3);
                            hat.owner.ApplyFreezeFrames(3);
                            other.ApplyFreezeFrames(3);
                            other.owner.ApplyFreezeFrames(3);

                            //PlayHatHitHatEffect(hit);
                            //PlayHitEffect(hit, other.velocity, hat.velocity, hat.velocity);
                            PlayHitHatEffect(hit, hat.velocity);

                            CalculateAccuracy();
                        }

                        if (!other.isCurrentlyAttached && !other.isFallingOff && !other.isBeingThrown && !hat.isCurrentlyAttached)
                        {
                            other.KnockBack(hat.velocity, hat.velocity.magnitude * 0.8f);
                        }
                    }
                    else
                    {
                        //PlayHatHitHatEffect(hit);
                    }

                    if ((hat.isCurrentlyAttached) || (other.isCurrentlyAttached))
                    {
                        continue;
                    }

                    if (!other.isCurrentlyAttached && !other.isFallingOff && !other.isBeingThrown)
                    {
                        //other.KnockBack (hat.velocity, hat.velocity.magnitude);
                    }
                }

                moveAmount.x = (hit.distance - skinWidth) * directionX;
                rayLength    = hit.distance;

                collisions.left  = directionX == -1;
                collisions.right = directionX == 1;

                if ((collisions.right || collisions.left) && !hat.isBeingAttached)
                {
                    collisions.shouldReflect = true;
                }

                if ((collisions.right || collisions.left) && hat.isBeingThrown && !hat.owner.isStunned && hit.transform.gameObject != hat.owner.gameObject)
                {
                    hat.AllowToComeBack();
                }
            }
        }
    }