protected void CheckFalling()
    {
        isFalling = true;
        //
        if (bAnim != null)
        {
            bAnim.Falling(true);
        }
        //
        for (int l = -1; l < 2; l += 2)
        {
            objHit = Physics2D.RaycastAll(transform.position + new Vector3(((rayOffSetX - 0.1f) * l) + (boxOffSetX * directionMultiplier.x), boxOffSetY * flipValue, 0),
                                          -Vector2.up * flipValue,
                                          rayOffSetY + distanceGraceForFalling);

            Debug.DrawRay(transform.position + new Vector3(((rayOffSetX - 0.1f) * l) + (boxOffSetX * directionMultiplier.x), boxOffSetY * flipValue, 0), -Vector2.up * flipValue, Color.grey);

            for (int i = 0; i < walkOn.Length; i++)
            {
                for (int j = 0; j < objHit.Length; j++)
                {
                    if (objHit[j].transform.tag == walkOn[i])
                    {
                        if (autoActivate && !stunned)
                        {
                            Debug.Log("AUTOUNFREEZE");
                            UnFreeze();
                            autoActivate = false;
                        }

                        if (Mathf.Abs(objHit[j].normal.x) < maxSlope) // So we cant jump on walls.
                        {
                            isFalling = false;


                            //
                            if (bAnim != null)
                            {
                                bAnim.Falling(false);
                            }
                            //
                            break;
                        }
                    }
                }
            }
        }
    }
示例#2
0
    private void ResetJump()
    {
        // If we asume we're always falling until told otherwise we get a more proper behaviour when falling off things.

        // An gracetime for how long u need to be falling before you do the "land" animation, otherwise small bumps will make u land which can look wierd
        // Also if we bind landanimation to stop playermovement that's realy frustrating

        // Count up always, as we are always assuming we are falling
        // reset it to 0 when we know we're at the ground.
        airbornTimer += Time.deltaTime;

        bool tempInAir = false;

        if (airbornTimer > timeUntilAirborn)
        {
            tempInAir = true;
            //
            //
            bodyAnim.Falling(true);
            armAnim.Falling(true);
            //
            //
        }

        for (int i = 0; i < resetJumpOn.Length; i++)
        {
            bool quickBreak = false;

            // We want 2 raycast in each corner, therefore this foor loop runs twice and gives me the value -1 and 1 so that i can use it to determine
            // which corner to put the ray in.
            for (int l = -1; l < 2; l += 2)
            {
                if (quickBreak)
                {
                    break;
                }

                objHit = Physics2D.RaycastAll(transform.position + new Vector3((capsuleRadiusX - 0.05f) * l, 0, 0) + new Vector3(capsuleOffSetX * transform.localScale.x, capsuleOffSetY * flippValue, 0),
                                              -Vector2.up * flippValue,
                                              capsuleRadiusY + distanceGraceForJump);

                Debug.DrawRay(transform.position + new Vector3((capsuleRadiusX - 0.05f) * l, 0, 0) + new Vector3(capsuleOffSetX * transform.localScale.x, capsuleOffSetY * flippValue, 0),
                              -Vector2.up * flippValue,
                              Color.red);

                for (int j = 0; j < objHit.Length; j++)
                {
                    if (objHit[j].transform.tag == resetJumpOn[i])
                    {
                        if (Mathf.Abs(objHit[j].normal.x) < wallNormal) // So we cant jump on walls.
                        {
                            if (inAir)
                            {
                                // LANDING
                                //play land sound
                                if (bodyAnim.GetJumpState() == false)
                                {
                                    bodyAnim.Land();
                                    armAnim.Land();

                                    movementAudio.Landing();
                                    landing = true;
                                }
                            }

                            /*
                             * if (resetJumpOn[i] == "MovingFloor" || objHit[j].transform.GetComponent<MovingPlatform>() != null)
                             *  transform.parent = objHit[j].transform;
                             */
                            // inAir = false;
                            tempInAir    = false;
                            lastSafe     = transform.position;
                            airbornTimer = 0;

                            //
                            //
                            bodyAnim.Falling(false);
                            armAnim.Falling(false);
                            //
                            //

                            // Send what type of ground the player is standig on
                            movementAudio.SetGroundType(objHit[j].transform.gameObject.layer);

                            quickBreak = true;
                        }
                    }
                }
            }
            inAir = tempInAir;
        }
    }