示例#1
0
    void TakeDamage()
    {
        Debug.Log("taking damage");
        meow.Play();

        currentLives--;
        if (currentLives > 0)           //test1
        {
            animator.SetTrigger("DamageTaken");
        }
        Debug.Log(currentLives);
        UpdateUI();
        if (currentLives <= 0)
        {
            this.GetComponent <Collider2D> ().enabled   = false;
            this.GetComponent <FollowObject> ().enabled = false;
            animator.SetTrigger("Dead"); //test1
            uiScript.EndGame();
            Destroy(gameObject, 2);      //test1
        }
        if (mainCam)
        {
            mainCam.addScreenShake(10);
        }
        remainingInvincibiltiyTime = invincibilityTime;

        //test

        Debug.Log(Physics2D.GetIgnoreCollision(collided, this.GetComponent <Collider2D>()));
    }
示例#2
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         Physics2D.GetIgnoreCollision(other.GetComponent <BoxCollider2D>(), gameObject.GetComponent <BoxCollider2D>());
     }
 }
示例#3
0
    private void FixedUpdate()
    {
        // Checks if player is touching the ground
        m_Grounded = false;
        Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);
        foreach (Collider2D temp_collider in colliders)
        {
            // Checks if collider and player are supposed to collide
            bool shouldCollide = !(Physics2D.GetIgnoreCollision(temp_collider, playerCollider) ||
                                   Physics2D.GetIgnoreLayerCollision(temp_collider.gameObject.layer, gameObject.layer));

            if (temp_collider.gameObject != gameObject && !temp_collider.isTrigger && shouldCollide)
            {
                m_Grounded = true;

                // Drops down platform
                if (dropDown && temp_collider.gameObject.layer == LayerMask.NameToLayer("EnvironmentObjects"))
                {
                    StartCoroutine(DropDownPlatform(temp_collider));
                }
            }
        }

        animator.SetBool("IsJumping", !m_Grounded);

        Move(horizontalMove);
        jump     = false;
        dropDown = false;
    }
示例#4
0
    // Use this for initialization
    public virtual void Start()
    {
        origColor = GetComponent <Renderer>().material.color;
        Collider2D[] playerCollider = new Collider2D[ArtrobotController.artTrans.
                                                     GetComponent <Rigidbody2D>().attachedColliderCount];
        ArtrobotController.artTrans.
        GetComponent <Rigidbody2D>().GetAttachedColliders(playerCollider);
        rgdCollider   = GetComponents <Collider2D>()[0];
        playerTrigger = ArtrobotController.player.GetComponents <Collider2D>()[0];
        Debug.Log("Collider count = " + ArtrobotController.artTrans.GetComponent <Rigidbody2D>().attachedColliderCount);

        foreach (Collider2D c in ArtrobotController.artTrans.GetComponents <Collider2D> ())
        {
            Debug.Log("Ignoring Collision with collider " + c.name);
            Physics2D.IgnoreCollision(rgdCollider, c, true);

            Debug.Log("rgdCollider name = " + rgdCollider.name);
        }
        int num = 0;

        foreach (Collider2D c in ArtrobotController.artTrans.GetComponents <Collider2D>())
        {
            Debug.Log("Ignore Collision = " + num + " " + Physics2D.GetIgnoreCollision(rgdCollider, c));
            Debug.Log("rgdCollider is trigger = " + c.isTrigger);
            num++;
        }
        audio = GetComponent <AudioSource>();
    }
示例#5
0
    /// <summary>
    /// </summary>
    /// <param name="collision">Any object trying to pass through a doorway</param>
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // Charged Interaction is Correct and we are NOT ignoring them
        if (
            !Physics2D.GetIgnoreCollision(collider1: collider, collider2: collision) &&
            collision.gameObject.layer == gameObject.layer
            )
        {
            // Play Power Down Sound
            doorSound.clip = doorOff;
            doorSound.Play();

            // Disable Collisions with that Object
            Physics2D.IgnoreCollision(
                collider1:  collider,
                collider2:  collision,
                ignore:     true
                );

            // Do Not Evaluate Any Other Conditions
            return;
        }

        // Any Other Interaction
        {
            // Play Power Failure Sound
            doorSound.clip = doorFail;
            doorSound.Play();

            // Do Not Evaluate Any Other Conditions
            return;
        }
    }
示例#6
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        // Ignoring Collisions
        if (Physics2D.GetIgnoreCollision(collider1: collider, collider2: collision))
        {
            // Play Power Up Sound
            doorSound.clip = doorOn;
            doorSound.Play();

            // Reactivate Collisions
            Physics2D.IgnoreCollision(
                collider1:  collider,
                collider2:  collision,
                ignore:     false
                );

            // Do Not Evaluate Any Other Conditions
            return;
        }

        // Any Other Interaction
        {
            // Play No Sound

            // Do Not Evaluate Any Other Conditions
            return;
        }
    }
示例#7
0
 void SaveSettings()
 {
     oldAngularDrag = rb.angularDrag;
     oldLinearDrag  = rb.drag;
     foreach (var collider in colliders)
     {
         oldIgnoreCollision[collider] = Physics2D.GetIgnoreCollision(collider, playerCollider);
     }
 }
示例#8
0
 protected void OnCollisionEnter2D(Collision2D coll)
 {
     if (isClimbing && coll.gameObject.tag == "Solid" && !Physics2D.GetIgnoreCollision(coll.collider, colli))
     {
         Debug.Log("add " + coll.gameObject.name);
         Physics2D.IgnoreCollision(coll.collider, colli);
         ignoreColliderMap[coll.collider] = 0;
     }
 }
示例#9
0
    public override void ResolvePendencies()
    {
        if (apostleStatusVariables.isOnAir)
        {
            if (lastFramePositionWhileFalling >= rigidbody2D.position.y && rigidbody2D.velocity.y < 0)
            {
                distanceWhileFalling += lastFramePositionWhileFalling - rigidbody2D.position.y;
            }

            if (apostleStatusVariables.canJump &&
                (rigidbody2D.velocity.y < 0 || MathHelpers.Approximately(rigidbody2D.velocity.y, 0, float.Epsilon)))
            {
                if (distanceWhileFalling >= minimumFallingDistanceForDamage)
                {
                    apostle.TakeDamage(minimumDamageForFalling * distanceWhileFalling /
                                       minimumFallingDistanceForDamage);
                }
                distanceWhileFalling           = 0;
                apostleStatusVariables.isOnAir = false;
                apostleController.RevokeControl(0.1f, true, ControlTypeToRevoke.AllMovement, monoBehaviour);
            }

            lastFramePositionWhileFalling = rigidbody2D.position.y;
        }
        else
        {
            lastFramePositionWhileFalling = 0;
        }

        if (!MathHelpers.Approximately(rigidbody2D.velocity.y, 0, float.Epsilon) &&
            MathHelpers.Approximately(apostleController.VerticalMovement, 0, float.Epsilon) &&
            apostleStatusVariables.isClimbingLadder)
        {
            PhysicsHelpers.ResetVelocityY(rigidbody2D);
        }

        if (!apostleStatusVariables.isClimbingStairs)
        {
//            PhysicsHelpers.IgnoreLayerCollision(rigidbody2D.gameObject.layer, LayerMask.NameToLayer("Stairs Ground"),
//                true);
            apostleCollisionHandler.SetLayerForCollisions(new[] { "Ground", "Ground Ignore" });

            var leftRayCollider  = apostleCollisionHandler.CastLeftwardRay(LayerMask.GetMask("Stairs Ground")).collider;
            var rightRayCollider =
                apostleCollisionHandler.CastRightwardRay(LayerMask.GetMask("Stairs Ground")).collider;

            if (leftRayCollider != null && !Physics2D.GetIgnoreCollision(capsuleCollider2D, leftRayCollider))
            {
                PhysicsHelpers.IgnoreCollision(capsuleCollider2D, leftRayCollider, true);
            }
            else if (rightRayCollider && !Physics2D.GetIgnoreCollision(capsuleCollider2D, rightRayCollider))
            {
                PhysicsHelpers.IgnoreCollision(capsuleCollider2D, rightRayCollider, true);
            }
        }
    }
        /// <summary>
        /// Whether or not a collision can be considered a valid overlap with the ground.
        /// </summary>
        /// <param name="collider">The collider</param>
        /// <returns>True if this is a valid "ground" overlap.</returns>
        public bool IsOverlap(Collider2D collider)
        {
            if (collider == null)
            {
                return(false);
            }

            return((parentCollider == null || !Physics2D.GetIgnoreCollision(collider, parentCollider)) && // Collision isn't purposefully ignored,
                   collider.CompareTag("Ground") &&                                                       // Collider is a ground object,
                   !collider.isTrigger);                                                                  // & Collider isn't a trigger.
        }
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.gameObject.GetComponent <FloorTag>() != null)
     {
         if (Physics2D.GetIgnoreCollision(other, GetCollider()))
         {
             Physics2D.IgnoreCollision(other, GetCollider(), false);
             wantToJumpDown = false;
         }
     }
 }
 void Update()
 {
     foreach (string tag in tags)
     {
         foreach (GameObject go in GameObject.FindGameObjectsWithTag(tag))
         {
             if (!Physics2D.GetIgnoreCollision(go.GetComponent <BoxCollider2D>(), GetComponent <BoxCollider2D>()) &&
                 go != gameObject)
             {
                 Physics2D.IgnoreCollision(go.GetComponent <BoxCollider2D>(), GetComponent <BoxCollider2D>());
             }
         }
     }
 }
示例#13
0
//	private CircleCollider2D circle;

    public override void OnCollisionEnter2D(Collision2D c)
    {
        base.OnCollisionEnter2D(c);
        if (c.gameObject.tag == "Bullet")
        {
            killMonster();
            Physics2D.GetIgnoreCollision(c.collider, GetComponent <BoxCollider2D> ());
        }
        else if (c.gameObject.tag == "Player")
        {
            audio1.Stop();
            inPursue = false;
        }
        Debug.Log(c.gameObject.tag);
    }
示例#14
0
        protected new void OnTriggerEnter2D(Collider2D other)
        {
            base.OnTriggerEnter2D(other);

            if (other.CompareTag("Player"))
            {
                if (col != null)
                {
                    if (!Physics2D.GetIgnoreCollision(col, other))
                    {
                        Physics2D.IgnoreCollision(col, other);
                    }
                }
            }
        }
示例#15
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            int id = other.gameObject.GetInstanceID();
            if (!isIn.ContainsKey(id))
            {
                isIn [id] = 0;
            }
            isIn [id] += 1;
            if (isIn [id] == 1)
            {
                bool isKlaus = other.name.CompareTo("Klaus") == 0;
                bool needDown;
                if (isKlaus)
                {
                    needDown = OneWaySingleton.Instance.GetNeedDownKlaus(colliderOneWay);
                }
                else
                {
                    needDown = OneWaySingleton.Instance.GetNeedDownK1(colliderOneWay);
                }
                if (!needDown)
                {
                    MoveState State = other.GetComponent <MoveState>();

                    if (EstoyAbajo(State))
                    {
                        if (!Physics2D.GetIgnoreCollision(colliderOneWay, State.colliders [0]))
                        {
                            for (int i = 0; i < State.colliders.Length; ++i)
                            {
                                Physics2D.IgnoreCollision(colliderOneWay, State.colliders [i], true);
                            }
                            if (other.name.CompareTo("Klaus") == 0)
                            {
                                OneWaySingleton.Instance.SetIsKlausOneWay(colliderOneWay, true);
                            }
                            else if (other.name.CompareTo("K1") == 0)
                            {
                                OneWaySingleton.Instance.SetIsK1OneWay(colliderOneWay, true);
                            }
                        }
                    }
                }
            }
        }
    }
示例#16
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Player"))
        {
            Debug.Log("Era pra morrer");
            col.transform.position = col.gameObject.GetComponent <PlayerCheckpoint>().currentCheckpoint.transform.position;
        }

        if (col.gameObject.CompareTag("Ghost"))
        {
            col.transform.position = col.gameObject.GetComponent <GhostCheckpoint>().spawnPoint.transform.position;
            col.GetComponent <Ghost_AI>().playerTrigger = false;
            Debug.Log(Physics2D.GetIgnoreCollision(col, playerCollider));
            Physics2D.IgnoreCollision(col, playerCollider, false);
        }
    }
示例#17
0
    private void HandlePlayerClimb(float horizontal, float vertical)
    {
        CheckCanClimb();

        if (PlayerMoveVertical(horizontal, vertical) && canPlayerClimbUp && !PlayerDiggingAnimation())
        {
            isPlayerClimbing = true;
        }

        if (PlayerMoveHorizontal(horizontal, vertical) && canPlayerClimbUp)
        {
            isPlayerClimbing = false;
        }

        // Handle climbing animation speed if animation DIG is stoped
        if (isPlayerClimbing && !PlayerDiggingAnimation())
        {
            Rigidbody2D.position = new Vector2(ladderPositionX, Rigidbody2D.position.y);
            Rigidbody2D.velocity = new Vector2(0, Rigidbody2D.velocity.y);

            animator.speed = Mathf.Abs(vertical);
        }
        else
        {
            animator.speed = 1;
        }

        // if player stop climbing set all players and ladders floor collisions to false
        foreach (Collider2D c in floorLaddersColliders.Values)
        {
            if (!isPlayerClimbing && c && Physics2D.GetIgnoreCollision(playerCollider2D, c))
            {
                Physics2D.IgnoreCollision(playerCollider2D, c, false);
            }
        }

        // We clean the dictionary after set all floor colliders to false
        if (!isPlayerClimbing)
        {
            floorLaddersColliders.Clear();
            resetCounter = 0;
        }

        // Set climping animation variables
        animator.SetBool("isClimbing", isPlayerClimbing);
        animator.SetFloat("climbSpeed", vertical);
    }
示例#18
0
文件: Spatial.cs 项目: vsugrob/Wyrms
    public static System.Func <RaycastHit2D, bool> IgnoreSelfCollisionPredicate(Collider2D collider)
    {
        if (collider == null)
        {
            return(hit => false);
        }
        else
        {
            return(hit => {
                var hitCollider = hit.collider;

                return hitCollider == collider ||
                hitCollider.attachedRigidbody == collider.attachedRigidbody ||
                Physics2D.GetIgnoreCollision(hitCollider, collider);
            });
        }
    }
示例#19
0
 private void CheckLastPassedThrough()
 {
     if (m_LastPassThrough != null)
     {
         foreach (Collider2D myc2d in m_MyColliders)
         {
             foreach (Collider2D c2d in m_LastPassThrough)
             {
                 if (Physics2D.GetIgnoreCollision(myc2d, c2d))
                 {
                     Physics2D.IgnoreCollision(myc2d, c2d, false);
                 }
             }
         }
         m_LastPassThrough = null;
         m_IsPassing       = false;
     }
 }
        // Update is called once per frame
        void Update()
        {
            OnGround         = false;
            _groundColliders = Physics2D.OverlapCircleAll((Vector2)transform.position + bottomOffset, groundCheckRadius, groundLayer);
            foreach (Collider2D groundCollider in _groundColliders)
            {
                if (Physics2D.GetIgnoreCollision(bodyCollider, groundCollider))
                {
                    continue;
                }
                else
                {
                    OnGround = true;
                }
            }

            _oneWayPlatform = Physics2D.OverlapCircle((Vector2)transform.position + bottomOffset, groundCheckRadius, oneWayPlatformLayer);
        }
示例#21
0
    public override void DoBeforeLeaving()
    {
        //  ManagerPause.UnSubscribeOnPauseGame(OnPauseGame);
        //ManagerPause.UnSubscribeOnResumeGame(OnResumeGame);

        //Set ladder false
        _rigidbody2D.gravityScale = storeGravityScale;
        if (move.LadderTop != null)
        {
            if (Physics2D.GetIgnoreCollision(move.LadderTop.colliderOneTop, move.colliders[0]))
            {
                for (int i = 0; i < move.colliders.Length; ++i)
                {
                    Physics2D.IgnoreCollision(move.LadderTop.colliderOneTop, move.colliders[i], false);
                }
            }
        }
        isForcing = false;
        anim.SetBool(AnimLadder, false);
    }
示例#22
0
        void SetCollideConnected()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            for (int i = 0, l = m_OldCollisionStates.Count; i < l; ++i)
            {
                var pair = m_OldCollisionStates [i];
                Physics2D.IgnoreCollision(pair.colliderA, pair.colliderB, pair.ignore);
            }

            m_OldCollisionStates.Clear();

            var collidersA = ((Rigidbody2DExt)cachedRigidbody2D).GetColliders();
            var collidersB = ((Rigidbody2DExt)connectedBody).GetColliders();

            for (int i = 0, lI = collidersA.Count; i < lI; ++i)
            {
                var colliderA = collidersA [i] as Collider2D;

                for (int j = 0, lJ = collidersB.Count; j < lJ; ++j)
                {
                    var colliderB = collidersB [j] as Collider2D;

                    m_OldCollisionStates.Add(new Collider2DPair
                    {
                        colliderA = colliderA,
                        colliderB = colliderB,
                        ignore    = Physics2D.GetIgnoreCollision(colliderA, colliderB)
                    });
                    Physics2D.IgnoreCollision(colliderA, colliderB, !m_CollideConnected);
                }
            }

            m_CollideConnectedCached = m_CollideConnected;

            m_ConnectedBodyCached = connectedBody;
        }
示例#23
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.CompareTag("Player"))
     {
         MoveState State   = other.GetComponent <MoveState>();
         bool      isKlaus = other.name.CompareTo("Klaus") == 0;
         bool      needDown;
         if (isKlaus)
         {
             needDown = OneWaySingleton.Instance.GetNeedDownKlaus(colliderOneWay);
         }
         else
         {
             needDown = OneWaySingleton.Instance.GetNeedDownK1(colliderOneWay);
         }
         if (EstoyArriba(State) && !needDown)
         {
             if (Physics2D.GetIgnoreCollision(colliderOneWay, State.colliders [0]))
             {
                 if (State._rigidbody2D.velocity.y < 0)
                 {
                     for (int i = 0; i < State.colliders.Length; ++i)
                     {
                         Physics2D.IgnoreCollision(colliderOneWay, State.colliders [i], false);
                     }
                     if (other.name.CompareTo("Klaus") == 0)
                     {
                         OneWaySingleton.Instance.SetIsKlausOneWay(colliderOneWay, false);
                     }
                     else if (other.name.CompareTo("K1") == 0)
                     {
                         OneWaySingleton.Instance.SetIsK1OneWay(colliderOneWay, false);
                     }
                 }
             }
         }
     }
 }
示例#24
0
    // Update is called once per frame
    void Update()
    {
        affected.Clear();

        hitColliders = Physics2D.OverlapCircleAll(transform.position, absorbRadius, layerMask);

        for (int i = 0; i < hitColliders.Length; i++)
        {
            if (hitColliders[i].tag == "Mana" && Physics2D.GetIgnoreCollision(collider, hitColliders[i]))
            {
                affected.Add(hitColliders[i].name);
            }
            else
            {
                Debug.Log("Eey, summat's wrong 'ere");
            }
        }

        if (affected.Count != 0)
        {
            PullMana(transform.position, affected);
        }
    }
示例#25
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        ship01Rigidbody.constraints = UnityEngine.RigidbodyConstraints2D.FreezeRotation;
        if (Physics2D.GetIgnoreCollision(ship01Collider, shadowCollider))
        {
            Debug.Log("--- collision between shadow & boat is ignored \n");
        }

        Collider2D collidee = collision.collider;

        if (collision.gameObject.tag == "Metaball_liquid")
        {
            //Debug.Log("contacting with water ---- \n");
            //Physics2D.IgnoreCollision(ship01Collider, collidee, true);
            ship01Rigidbody.velocity = floatingSpeed * transform.up;
            //collision.enabled = false;
            //Vector3 impulse = collision.impulse;
            //ship01Rigidbody.AddForce(-impulse, ForceMode.Impulse);//refrain the boat from colliding impulses
        }
        // if(collision.gameObject.tag == "Player")
        // {
        //     Debug.Log("ship01 colliding with player ---- \n");
        // }
    }
    public static void testForInfringement()
    {
        List <Collider2D> cols = new List <Collider2D>();

        for (int i = 0; i < SceneManager.sceneCount; i++)
        {
            foreach (GameObject go in SceneManager.GetSceneAt(i).GetRootGameObjects())
            {
                cols.AddRange(go.GetComponentsInChildren <Collider2D>(true));
            }
        }
        Debug.Log(cols.Count);
        cols.TrimExcess();

        ////Make sure we are not checking with the infringer
        //for (int i = 0; i < cols.Count; i ++)
        //{
        //    if (cols[i] == possibleInfringer)
        //        cols.RemoveAt(i);
        //}

        //lets try to sketch out a custom collider.


        foreach (Collider2D col2d1 in cols)
        {
            foreach (Collider2D col2d2 in cols)
            {
                //if((col2d2.name == "ObjectColForOtherObjects" && col2d1.name.Contains("QuestionMarkBox")))
                //{
                //    Debug.Log(col2d1);
                //    //Debug.Log(col2d1.bounds.center);
                //    //Debug.Log(col2d1.bounds);
                //    Debug.Log(col2d2);
                //    //Debug.Log(col2d2.bounds);
                //    //Debug.Log(col2d2.bounds.center);
                //    //Debug.Break();
                //}

                if
                (
                    (col2d1.isActiveAndEnabled && !col2d1.isTrigger) &&
                    (col2d2.isActiveAndEnabled && !col2d2.isTrigger) &&
                    !Physics2D.GetIgnoreCollision(col2d1, col2d2) &&
                    !Physics2D.GetIgnoreLayerCollision(col2d1.gameObject.layer, col2d2.gameObject.layer) &&
                    col2d1 != col2d2 &&
                    (col2d1.GetType() != typeof(EdgeCollider2D) && col2d2.GetType() != typeof(EdgeCollider2D))
                )
                {
                    Rect oneRect = new Rect(col2d1.bounds.min, new Vector2(col2d1.bounds.size.x, col2d1.bounds.size.y));
                    Rect twoRect = new Rect(col2d2.bounds.min, new Vector2(col2d2.bounds.size.x, col2d2.bounds.size.y));

                    if (col2d1.bounds.Intersects(col2d2.bounds) && (col2d2.GetComponent <Rigidbody2D>() != null || col2d2.gameObject.GetComponentInParent <Rigidbody2D>() != null))
                    {
                        Debug.Log("Yeah");
                        Vector3 NormalizedDirection = (twoRect.position - oneRect.position).normalized;
                        //Debug.Log(NormalizedDirection);
                        int e = 0;
                        foreach (Collider2D col2d3 in cols)
                        {
                            if (col2d3 != col2d1 && col2d3 != col2d2 && col2d3.enabled && !col2d3.isTrigger && !Physics2D.GetIgnoreLayerCollision(col2d2.gameObject.layer, col2d3.gameObject.layer) && col2d3.GetType() != typeof(EdgeCollider2D))
                            {
                                while (col2d2.bounds.Intersects(col2d3.bounds))
                                {
                                    e++;
                                    Debug.Log(e);
                                    //KEEP MOVING. Were still in something.
                                    col2d2.GetComponentInParent <Rigidbody2D>().gameObject.transform.position += e * (NormalizedDirection + col2d2.bounds.extents);
                                    Debug.Log("noep");
                                }
                            }
                        }
                        //LETS TRY USING RAYS.
                        Ray testRay = new Ray(col2d1.bounds.center, NormalizedDirection);
                        Debug.DrawRay(testRay.origin, testRay.direction, Color.blue, 1f);
                    }

                    //else
                    //{
                    //    if (col2d1.bounds.Intersects(col2d2.bounds) && col2d1.GetComponent<Rigidbody2D>() != null)
                    //    {
                    //        Vector3 NormalizedDirection = (oneRect.position - twoRect.center).normalized;
                    //        //Debug.Log(NormalizedDirection);
                    //        int e = 0;
                    //        foreach (Collider2D col2d3 in cols)
                    //        {
                    //            if (col2d3 != col2d1 && col2d3 != col2d2 && col2d3.enabled && !col2d3.isTrigger && !Physics2D.GetIgnoreLayerCollision(col2d1.gameObject.layer, col2d3.gameObject.layer) && col2d3.GetType() != typeof(EdgeCollider2D))
                    //            {

                    //                if (col2d1.bounds.Intersects(col2d3.bounds))
                    //                {
                    //                    e++;
                    //                    Debug.Log(e);
                    //                    //KEEP MOVING. Were still in something.
                    //                    col2d2.transform.position += e * (NormalizedDirection + col2d2.bounds.extents);
                    //                    Debug.Log("noep");
                    //                }

                    //            }
                    //        }
                    //    }
                    //}
                }
            }
        }
    }
示例#27
0
    void FixedUpdate()
    {
        DrawDebug();

        float frameTime = Time.deltaTime;

        if (frameTime <= 0)
        {
            return;
        }

        m_position = transform.position;

        Vector2 collisionPos = m_position + m_offset;
        Vector2 localVelocity;

        m_onGround = false;
        if (m_gravityScale > 0)
        {
            m_velocity.y -= s_gravity * m_gravityMultiplier * m_gravityScale * frameTime;
            localVelocity = new Vector2(0, m_velocity.y * frameTime);

            // Trace floor
            if (localVelocity.y < 0)
            {
                RaycastHit2D hit2D = Physics2D.BoxCast(collisionPos, m_size, 0, localVelocity, -localVelocity.y);
                if (hit2D)
                {
                    m_position  += localVelocity * hit2D.fraction + (hit2D.normal * 0.01f);
                    m_velocity.y = 0;
                    m_onGround   = true;

                    collisionPos.y = m_position.y + m_offset.y;

                    if (hit2D.transform.GetComponent <MovingPlatform>() != null)
                    {
                        transform.SetParent(hit2D.transform);
                    }
                    else
                    {
                        transform.SetParent(null);
                    }
                }
            }

            if (!m_onGround)
            {
                transform.SetParent(null);
            }
        }

        // Trace walking
        m_hitWall     = false;
        m_hitCeiling  = false;
        localVelocity = m_velocity * frameTime;

        for (uint resolveCount = 0; resolveCount < 3; resolveCount++)
        {
            float magnitude = localVelocity.magnitude;
            if (magnitude > 0.0f)
            {
                RaycastHit2D hit2D = Physics2D.BoxCast(collisionPos, m_size, 0, localVelocity, magnitude);

                bool collide = false;
                if (hit2D)
                {
                    CollisionCreator collision = hit2D.transform.GetComponent <CollisionCreator>();
                    if (collision && collision.isOneway)
                    {
                        collide = false;
                    }
                    else
                    {
                        collide = !Physics2D.GetIgnoreCollision(hit2D.collider, m_collider);
                    }
                }

                if (collide)
                {
                    if (Mathf.Abs(hit2D.normal.x) > m_WallNormal)
                    {
                        m_hitWall = true;
                    }
                    else
                    {
                        // Debug.Log (hit2D.transform.name + ":" + hit2D.transform.position);

                        m_hitCeiling = true;
                    }
                    m_wallDirection = Mathf.Sign(hit2D.normal.x);

                    /*
                     * if(m_hitWall) {
                     *      localVelocity.x = 0;
                     * }
                     * m_position += (localVelocity * hit2D.fraction);// + (hit2D.normal * 0.01f);
                     *
                     * collisionPos = m_position + m_offset;
                     * localVelocity =  -(1.0f * Vector2.Dot(hit2D.normal, localVelocity) * hit2D.normal) + localVelocity;
                     * // localVelocity *= 1.0f - hit2D.fraction;
                     */
                    collisionPos = m_position + (localVelocity * hit2D.fraction);

                    // Hack - would be nice to remove this
                    if (m_hitWall)
                    {
                        m_position.x  += (localVelocity.x * hit2D.fraction) + (hit2D.normal.x * 0.01f);
                        collisionPos.y = m_position.y;
                    }
                    else
                    {
                        collisionPos.x = m_position.x;
                    }

                    collisionPos += m_offset;
                    localVelocity = -(1.0f * Vector2.Dot(hit2D.normal, localVelocity) * hit2D.normal) + localVelocity;
                }
                else
                {
                    m_position += localVelocity;
                    break;
                }
            }
        }
        m_velocity         = localVelocity / frameTime; // Change this to distance travelled then we can modify the velocity internally
        transform.position = m_position;

        if (m_showDebug)
        {
            Debug.Log(Time.frameCount +
                      " :" + transform.name +
                      " :" + " OnGround:" + m_onGround +
                      " HitWall:" + m_hitWall +
                      " Ground=" + ((transform.parent == null) ? "null" : transform.parent.name));
        }
    }
    //Collision
    void OnTriggerEnter2D(Collider2D other)
    {
        switch (other.gameObject.tag)
        {
        case "GenericBullet":
        {
            if (other.gameObject.GetComponent <BulletObject>().CanHitPlayer)
            {
                Destroy(other.gameObject);

                if (characterState == CHARACTER_STATE.CHARACTERSTATE_NORMAL)
                {
                    DecreaseCharacterHealth(other.gameObject.GetComponent <BulletObject>().BulletDamage *BerserkDamageModifier);

                    if (characterHealth <= 0)
                    {
                        SceneManager.LoadScene("GameOver");
                    }
                }
            }

            goto default;
        }

        case "Ground":
        {
            if (Physics2D.GetIgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.GetComponent <Collider2D>()))
            {
                Physics2D.IgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.GetComponent <Collider2D>(), false);
            }

            goto default;
        }

        case "InvincibilityPowerup":
        {
            if (characterState == CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE)
            {
                //If player already invincible, reset the timer
                InvincibilityTimer = InvincibilityTimeLimit;
                return;
            }

            characterState = CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE;
            Destroy(other.gameObject);

            //Create a shield around player
            GameObject shield      = Instantiate(Resources.Load("shield") as GameObject, gameObject.transform.position, gameObject.transform.rotation, gameObject.transform);
            Image      shieldImage = shield.GetComponent <Image>();
            var        tempcolour  = shieldImage.color;
            tempcolour.a      = 0.5f;
            shieldImage.color = tempcolour;

            goto default;
        }

        case "HealthPowerup":
        {
            if (characterHealth >= characterHealthLimit)
            {
                return;
            }

            IncreaseCharacterHealth(20);

            if (characterHealth > characterHealthLimit)
            {
                characterHealth = characterHealthLimit;
            }

            Destroy(other.gameObject);

            goto default;
        }

        case "BerserkPowerup":
        {
            if (isBerserk)
            {
                return;
            }

            isBerserk            = true;
            spriteRenderer.color = BerserkColour;
            Destroy(other.gameObject);

            //Modifiers
            BerserkDamageModifier     = 0.75f;
            BerserkMovementModifer    = 1.25f;
            BerserkShootSpeedModifier = 1.25f;

            goto default;
        }

        case "fall":
        {
            SceneManager.LoadScene("GameOver");
            break;
        }

        case "Weapon":
        {
            Destroy(other.gameObject);

            //Check if player already has the weapon
            foreach (WeaponBase Weapon in WeaponsEquipped)
            {
                if (Weapon.WeaponName == other.name)
                {
                    return;
                }
            }

            if (other.name == "LMG")
            {
                WeaponsEquipped.Add(new LMG());
            }
            else if (other.name == "Minigun")
            {
                WeaponsEquipped.Add(new Minigun());
            }
            else if (other.name == "Pistol")
            {
                WeaponsEquipped.Add(new Pistol());
            }
            else if (other.name == "Revolver")
            {
                WeaponsEquipped.Add(new Revolver());
            }
            else if (other.name == "Rifle")
            {
                WeaponsEquipped.Add(new Rifle());
            }
            else if (other.name == "AK47")
            {
                WeaponsEquipped.Add(new AK47());
            }
            else if (other.name == "Carbine")
            {
                WeaponsEquipped.Add(new Carbine());
            }
            else if (other.name == "RPG")
            {
                WeaponsEquipped.Add(new RPG());
            }

            //Equip the newly picked up weapon
            CurrentWeapon = WeaponsEquipped.Count - 1;

            break;
        }

        case "LevelEnd":
        {
            SceneTransition sceneTransition = new SceneTransition();
            sceneTransition.Tolevelend();
            break;
        }

        default:
            break;
        }

        if (other.gameObject.name == "IgnoreCollisionTrigger")
        {
            if (!Physics2D.GetIgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.transform.parent.GetComponent <Collider2D>()))
            {
                Physics2D.IgnoreCollision(gameObject.GetComponent <Collider2D>(), other.gameObject.transform.parent.GetComponent <Collider2D>());
            }
        }
        if (other.gameObject.tag == "Checkpoint")
        {
            respawnpoint = other.transform.position;
            Destroy(other.gameObject);
            lol++;
            PlayerPrefs.SetFloat("savecheckpoint", lol);
            PlayerPrefs.SetFloat("respawnhere", respawnpoint.x);
            PlayerPrefs.SetFloat("respawnhere1", respawnpoint.y);
        }
    }
示例#29
0
    public MoveResult Move(PlayerController.Direction D, bool ApplyPhysicsBetweenPlayers = true, bool RecordEvent = true, FixedTickValue MoveValue = null)
    {
        if (Freeze)
        {
            return(MoveResult.CannotMove);
        }
        //if (!CanMove()) return MoveResult.IsAnimating;

        MoveResult NeedToBeMoved = MoveResult.CannotMove;

        if (D != PlayerController.Direction.NONE)
        {
            var     Direction = PlayerController.Directionf[(int)D];
            Vector3 Dir3      = new Vector3(Direction.x, Direction.y, 0);
            // WALL HITS
            RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position + (0.6f * Dir3), Dir3, 0.5f, wallmask);
            if (hits.Length != 0)
            {
                UpdatePositionBump(Direction);
                return(MoveResult.CannotMove);
            }
            // MOVABLE HITS
            RaycastHit2D[] hitsm = Physics2D.RaycastAll(transform.position + (0.6f * Dir3), Dir3, 0.5f, movablemask);
            hitsm = hitsm.Where(val => (val.collider.gameObject != this.gameObject)).ToArray(); // filter our own gameobject

            if (!ApplyPhysicsBetweenPlayers)
            {
                hitsm = hitsm.Where(val => (val.collider.gameObject.GetComponent <PlayerController>() == null)).ToArray(); // filter our own gameobject
            }
            if (hitsm.Length == 0)
            {
                NeedToBeMoved = MoveResult.CanMove;
            }
            else
            {
                foreach (RaycastHit2D hit in hitsm)
                {
                    if (hit.collider.gameObject != this.gameObject) // not necessary should already be filtered
                    {
                        if (hit.collider != null)
                        {
                            // Detect if we are colliding with a player
                            // If the player asked for the same direction than us last event
                            // We dont execute the move and simply move this object because physic
                            // is executed in a certain order
                            var PC   = hit.collider.GetComponent <PlayerController>();
                            var Mov  = hit.collider.GetComponent <Movable>();
                            var mePC = GetComponent <PlayerController>();
                            if (Mov)
                            {
                                if (PC && mePC)
                                {
                                    if (Physics2D.GetIgnoreCollision(mePC.GetComponent <BoxCollider2D>(), PC.GetComponent <BoxCollider2D>()))
                                    {
                                        NeedToBeMoved = MoveResult.CanMove;
                                    }
                                    else
                                    {
                                        NeedToBeMoved = Mov.Move(D, true, true, MoveValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (NeedToBeMoved == MoveResult.CanMove)
            {
                UpdatePosition(Direction);
                if (RecordEvent && MoveValue != null)
                {
                    MoveValue.AddObserver(new MoveValue(this, D));
                }
            }

            if (D != PlayerController.Direction.NONE && NeedToBeMoved == MoveResult.CannotMove)
            {
                // Do a bump into wall animation
                UpdatePositionBump(Direction);
            }
        }
        return(NeedToBeMoved);
    }
示例#30
0
    protected override void FixedUpdateChild()
    {
        if (!ManagerPause.Pause)
        {
            if (!isForcing)
            {
                if (move.LadderTop != null)
                {
                    if (!Physics2D.GetIgnoreCollision(move.LadderTop.colliderOneTop, move.colliders[0]))
                    {
                        for (int i = 0; i < move.colliders.Length; ++i)
                        {
                            Physics2D.IgnoreCollision(move.LadderTop.colliderOneTop, move.colliders[i], true);
                        }
                    }
                }
                #region Check ground
                isGround = Physics2D.OverlapCircleNonAlloc(groundCheck.position, groundRadiusTotal, result, whatIsGround) > 0;
                //Fix Loco
                for (int i = 0; i < result.Length; ++i)
                {
                    if (result[i] != null)
                    {
                        if (result[i] == move.LadderTop)
                        {
                            isGround = false;
                            break;
                        }
                    }
                }
                //
                anim.SetBool("isGround", isGround);
                #endregion

                float speedX = 0;
                float speedY = buttonMapAxis[VerticalAxis] * SpeedY;
                if (move.getOnPlatformLadder() != null)
                {
                    if ((move.getOnPlatformLadder().velocity.y > 0 && speedY > 0) ||
                        (move.getOnPlatformLadder().velocity.y < 0 && speedY < 0))
                    {
                        speedY = speedY * move.percentPlatformMoveSameDir + move.getOnPlatformLadder().velocity.y;
                    }
                    else if ((move.getOnPlatformLadder().velocity.y > 0 && speedY < 0) ||
                             (move.getOnPlatformLadder().velocity.y < 0 && speedY > 0))
                    {
                        speedY = speedY * move.percentPlatformMoveOposDir + move.getOnPlatformLadder().velocity.y;
                    }
                    else
                    {
                        speedY = speedY + move.getOnPlatformLadder().velocity.y;
                    }


                    speedX = move.getOnPlatformLadder().velocity.x;
                }
                _rigidbody2D.velocity = new Vector2(speedX, speedY);
                anim.SetFloat(AnimLadderSpeed, Mathf.Abs(buttonMapAxis[VerticalAxis]));
            }
            else
            {
                if (move.getOnPlatformLadder() != null)
                {
                    _rigidbody2D.velocity = move.getOnPlatformLadder().velocity;
                }
            }
        }
    }